@@ -11,18 +11,30 @@ const h2 = require('http2');
1111const net = require ( 'net' ) ;
1212const { NghttpError } = require ( 'internal/http2/util' ) ;
1313const h2test = require ( '../common/http2' ) ;
14+ let client ;
1415
1516const server = h2 . createServer ( ) ;
1617server . on ( 'stream' , common . mustCall ( ( stream ) => {
1718 stream . respond ( ) ;
18- stream . end ( 'ok' ) ;
1919
20- stream . on ( 'error' , common . expectsError ( {
21- code : 'ERR_HTTP2_ERROR' ,
22- constructor : NghttpError ,
23- message : 'Stream was already closed or invalid'
24- } ) ) ;
25- stream . on ( 'close' , common . mustCall ( ) ) ;
20+ if ( stream . id === 3 ) {
21+ stream . on ( 'close' , ( ) => {
22+ // A second Stream ID 1 frame should fail.
23+ // This will cause an error to occur because the client is
24+ // attempting to reuse an already closed stream. This must
25+ // cause the server session to be torn down.
26+ client . write ( id1 . data ) ;
27+ // This Stream ID 5 frame will never make it to the server.
28+ client . write ( id5 . data ) ;
29+ } ) ;
30+ stream . end ( 'ok' ) ;
31+ } else {
32+ stream . on ( 'error' , common . expectsError ( {
33+ code : 'ERR_HTTP2_ERROR' ,
34+ constructor : NghttpError ,
35+ message : 'Stream was already closed or invalid'
36+ } ) ) ;
37+ }
2638
2739 // Stream ID 5 should never reach the server
2840 assert . notStrictEqual ( stream . id , 5 ) ;
@@ -45,23 +57,14 @@ const id3 = new h2test.HeadersFrame(3, h2test.kFakeRequestHeaders, 0, true);
4557const id5 = new h2test . HeadersFrame ( 5 , h2test . kFakeRequestHeaders , 0 , true ) ;
4658
4759server . listen ( 0 , ( ) => {
48- const client = net . connect ( server . address ( ) . port , ( ) => {
60+ client = net . connect ( server . address ( ) . port , ( ) => {
4961 client . write ( h2test . kClientMagic , ( ) => {
5062 client . write ( settings . data , ( ) => {
5163 client . write ( settingsAck . data ) ;
5264 // Stream ID 1 frame will make it OK.
5365 client . write ( id1 . data , ( ) => {
5466 // Stream ID 3 frame will make it OK.
55- client . write ( id3 . data , ( ) => {
56- // A second Stream ID 1 frame should fail.
57- // This will cause an error to occur because the client is
58- // attempting to reuse an already closed stream. This must
59- // cause the server session to be torn down.
60- client . write ( id1 . data , ( ) => {
61- // This Stream ID 5 frame will never make it to the server
62- client . write ( id5 . data ) ;
63- } ) ;
64- } ) ;
67+ client . write ( id3 . data ) ;
6568 } ) ;
6669 } ) ;
6770 } ) ;
0 commit comments