@@ -60,6 +60,8 @@ const {
60
60
owner_symbol,
61
61
} ,
62
62
} = require ( 'internal/async_hooks' ) ;
63
+ const { AsyncResource } = require ( 'async_hooks' ) ;
64
+
63
65
const {
64
66
AbortError,
65
67
aggregateTwoErrors,
@@ -241,6 +243,7 @@ const kPendingRequestCalls = Symbol('kPendingRequestCalls');
241
243
const kProceed = Symbol ( 'proceed' ) ;
242
244
const kProtocol = Symbol ( 'protocol' ) ;
243
245
const kRemoteSettings = Symbol ( 'remote-settings' ) ;
246
+ const kRequestAsyncResource = Symbol ( 'requestAsyncResource' ) ;
244
247
const kSelectPadding = Symbol ( 'select-padding' ) ;
245
248
const kSentHeaders = Symbol ( 'sent-headers' ) ;
246
249
const kSentTrailers = Symbol ( 'sent-trailers' ) ;
@@ -408,7 +411,11 @@ function onSessionHeaders(handle, id, cat, flags, headers, sensitiveHeaders) {
408
411
originSet . delete ( stream [ kOrigin ] ) ;
409
412
}
410
413
debugStream ( id , type , "emitting stream '%s' event" , event ) ;
411
- process . nextTick ( emit , stream , event , obj , flags , headers ) ;
414
+ const reqAsync = stream [ kRequestAsyncResource ] ;
415
+ if ( reqAsync )
416
+ reqAsync . runInAsyncScope ( process . nextTick , null , emit , stream , event , obj , flags , headers ) ;
417
+ else
418
+ process . nextTick ( emit , stream , event , obj , flags , headers ) ;
412
419
}
413
420
if ( endOfStream ) {
414
421
stream . push ( null ) ;
@@ -1797,6 +1804,8 @@ class ClientHttp2Session extends Http2Session {
1797
1804
stream [ kSentHeaders ] = headers ;
1798
1805
stream [ kOrigin ] = `${ headers [ HTTP2_HEADER_SCHEME ] } ://` +
1799
1806
`${ getAuthority ( headers ) } ` ;
1807
+ const asyncRes = new AsyncResource ( 'PendingRequest' ) ;
1808
+ stream [ kRequestAsyncResource ] = asyncRes ;
1800
1809
1801
1810
// Close the writable side of the stream if options.endStream is set.
1802
1811
if ( options . endStream )
@@ -1819,7 +1828,7 @@ class ClientHttp2Session extends Http2Session {
1819
1828
}
1820
1829
}
1821
1830
1822
- const onConnect = requestOnConnect . bind ( stream , headersList , options ) ;
1831
+ const onConnect = asyncRes . bind ( requestOnConnect . bind ( stream , headersList , options ) ) ;
1823
1832
if ( this . connecting ) {
1824
1833
if ( this [ kPendingRequestCalls ] !== null ) {
1825
1834
this [ kPendingRequestCalls ] . push ( onConnect ) ;
0 commit comments