File tree 2 files changed +39
-4
lines changed
2 files changed +39
-4
lines changed Original file line number Diff line number Diff line change @@ -434,23 +434,27 @@ function sessionListenerRemoved(name) {
434
434
// Also keep track of listeners for the Http2Stream instances, as some events
435
435
// are emitted on those objects.
436
436
function streamListenerAdded ( name ) {
437
+ const session = this [ kSession ] ;
438
+ if ( ! session ) return ;
437
439
switch ( name ) {
438
440
case 'priority' :
439
- this [ kSession ] [ kNativeFields ] [ kSessionPriorityListenerCount ] ++ ;
441
+ session [ kNativeFields ] [ kSessionPriorityListenerCount ] ++ ;
440
442
break ;
441
443
case 'frameError' :
442
- this [ kSession ] [ kNativeFields ] [ kSessionFrameErrorListenerCount ] ++ ;
444
+ session [ kNativeFields ] [ kSessionFrameErrorListenerCount ] ++ ;
443
445
break ;
444
446
}
445
447
}
446
448
447
449
function streamListenerRemoved ( name ) {
450
+ const session = this [ kSession ] ;
451
+ if ( ! session ) return ;
448
452
switch ( name ) {
449
453
case 'priority' :
450
- this [ kSession ] [ kNativeFields ] [ kSessionPriorityListenerCount ] -- ;
454
+ session [ kNativeFields ] [ kSessionPriorityListenerCount ] -- ;
451
455
break ;
452
456
case 'frameError' :
453
- this [ kSession ] [ kNativeFields ] [ kSessionFrameErrorListenerCount ] -- ;
457
+ session [ kNativeFields ] [ kSessionFrameErrorListenerCount ] -- ;
454
458
break ;
455
459
}
456
460
}
Original file line number Diff line number Diff line change
1
+ 'use strict' ;
2
+
3
+ const common = require ( '../common' ) ;
4
+ if ( ! common . hasCrypto )
5
+ common . skip ( 'missing crypto' ) ;
6
+ const http2 = require ( 'http2' ) ;
7
+
8
+ // Regression test for https://github.com/nodejs/node/issues/29457:
9
+ // HTTP/2 stream event listeners can be added and removed after the
10
+ // session has been destroyed.
11
+
12
+ const server = http2 . createServer ( ( req , res ) => {
13
+ res . end ( 'Hi!\n' ) ;
14
+ } ) ;
15
+
16
+ server . listen ( 0 , common . mustCall ( ( ) => {
17
+ const client = http2 . connect ( `http://localhost:${ server . address ( ) . port } ` ) ;
18
+ const headers = { ':path' : '/' } ;
19
+ const req = client . request ( headers ) ;
20
+
21
+ req . on ( 'close' , common . mustCall ( ( ) => {
22
+ req . removeAllListeners ( ) ;
23
+ req . on ( 'priority' , common . mustNotCall ( ) ) ;
24
+ server . close ( ) ;
25
+ } ) ) ;
26
+
27
+ req . on ( 'priority' , common . mustNotCall ( ) ) ;
28
+ req . on ( 'error' , common . mustCall ( ) ) ;
29
+
30
+ client . destroy ( ) ;
31
+ } ) ) ;
You can’t perform that action at this time.
0 commit comments