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 @@ -426,23 +426,27 @@ function sessionListenerRemoved(name) {
426
426
// Also keep track of listeners for the Http2Stream instances, as some events
427
427
// are emitted on those objects.
428
428
function streamListenerAdded ( name ) {
429
+ const session = this [ kSession ] ;
430
+ if ( ! session ) return ;
429
431
switch ( name ) {
430
432
case 'priority' :
431
- this [ kSession ] [ kNativeFields ] [ kSessionPriorityListenerCount ] ++ ;
433
+ session [ kNativeFields ] [ kSessionPriorityListenerCount ] ++ ;
432
434
break ;
433
435
case 'frameError' :
434
- this [ kSession ] [ kNativeFields ] [ kSessionFrameErrorListenerCount ] ++ ;
436
+ session [ kNativeFields ] [ kSessionFrameErrorListenerCount ] ++ ;
435
437
break ;
436
438
}
437
439
}
438
440
439
441
function streamListenerRemoved ( name ) {
442
+ const session = this [ kSession ] ;
443
+ if ( ! session ) return ;
440
444
switch ( name ) {
441
445
case 'priority' :
442
- this [ kSession ] [ kNativeFields ] [ kSessionPriorityListenerCount ] -- ;
446
+ session [ kNativeFields ] [ kSessionPriorityListenerCount ] -- ;
443
447
break ;
444
448
case 'frameError' :
445
- this [ kSession ] [ kNativeFields ] [ kSessionFrameErrorListenerCount ] -- ;
449
+ session [ kNativeFields ] [ kSessionFrameErrorListenerCount ] -- ;
446
450
break ;
447
451
}
448
452
}
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