@@ -104,20 +104,29 @@ const stall = (stream) => { stream.setBody(stallingBody(1000)); };
104104 assert . strictEqual ( threw , undefined ) ;
105105}
106106
107- // Same with a nonzero stopSending code. The peer answers our STOP_SENDING with
108- // a RESET_STREAM carrying it, which rejects closed - but the read is still our
109- // own abort, so it is reported by policy rather than as that reset. This is
110- // the one case where the read and closed facets deliberately disagree.
107+ // A nonzero stopSending code is an error this end raised, so it is reported
108+ // under either policy and carries that code. The peer answers our
109+ // STOP_SENDING with a RESET_STREAM echoing it, which is what rejects closed -
110+ // but the read reports our own abort rather than attributing it to the peer,
111+ // and does so whether or not that answer has arrived yet.
111112for ( const truncatedReads of [ 'error' , 'allow' ] ) {
112- const { received, threw, closedError } = await readStream ( stall , {
113- clientOptions : { truncatedReads } ,
114- onFirstChunk : ( { stream } ) => stream . stopSending ( 7n ) ,
115- } ) ;
116- assert . ok ( received > 0 ) ;
117- assert . strictEqual ( threw ?. code ,
118- truncatedReads === 'error' ? 'ERR_QUIC_STREAM_ABORTED' : undefined ) ;
119- assert . strictEqual ( closedError ?. code , 'ERR_QUIC_APPLICATION_ERROR' ) ;
120- assert . strictEqual ( closedError . errorCode , 7n ) ;
113+ for ( const awaitEcho of [ false , true ] ) {
114+ const peerReset = Promise . withResolvers ( ) ;
115+ const { received, threw, closedError } = await readStream ( stall , {
116+ clientOptions : { truncatedReads } ,
117+ beforeIterate : ( { stream } ) => { stream . onreset = ( ) => peerReset . resolve ( ) ; } ,
118+ onFirstChunk : async ( { stream } ) => {
119+ stream . stopSending ( 7n ) ;
120+ // For the 2nd pass, wait until we receive the corresponding reset:
121+ if ( awaitEcho ) await peerReset . promise ;
122+ } ,
123+ } ) ;
124+ assert . ok ( received > 0 ) ;
125+ assert . strictEqual ( threw ?. code , 'ERR_QUIC_STREAM_ABORTED' ) ;
126+ assert . strictEqual ( threw . errorCode , 7n ) ;
127+ assert . strictEqual ( closedError ?. code , 'ERR_QUIC_APPLICATION_ERROR' ) ;
128+ assert . strictEqual ( closedError . errorCode , 7n ) ;
129+ }
121130}
122131
123132// A peer abruptly destroying its session truncates the read too. That
0 commit comments