Skip to content

Commit aad2e77

Browse files
Qardwatson
authored andcommitted
fix(async_hooks): properly update sync flag (#1306)
1 parent 6096fbd commit aad2e77

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

lib/instrumentation/async-hooks.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,14 @@ module.exports = function (ins) {
8080
}
8181

8282
function before (asyncId) {
83+
const span = activeSpans.get(asyncId)
84+
if (span) {
85+
span.sync = false
86+
}
87+
const transaction = span ? span.transaction : activeTransactions.get(asyncId)
88+
if (transaction) {
89+
transaction.sync = false
90+
}
8391
ins.bindingSpan = null
8492
}
8593

test/instrumentation/async-hooks.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,20 @@ test('post-defined, post-resolved promise', function (t) {
121121
})
122122
})
123123

124+
test('sync/async tracking', function (t) {
125+
var trans = agent.startTransaction()
126+
t.equal(trans.sync, true)
127+
128+
var span = agent.startSpan()
129+
t.equal(span.sync, true)
130+
131+
setImmediate(() => {
132+
t.equal(trans.sync, false)
133+
t.equal(span.sync, false)
134+
t.end()
135+
})
136+
})
137+
124138
function twice (fn) {
125139
setImmediate(fn)
126140
setImmediate(fn)

0 commit comments

Comments
 (0)