Skip to content

Commit d8ceea3

Browse files
committed
quic: handle stop sending
1 parent 45adede commit d8ceea3

5 files changed

Lines changed: 47 additions & 5 deletions

File tree

‎doc/api/quic.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3496,8 +3496,8 @@ selects how the stream's async iterator reports this:
34963496

34973497
* `'ignore'` - The truncation itself is ignored: only a stream or connection
34983498
error is reported, and any clean abort/cancellation or similar simply ends
3499-
the stream. A peer reset whose application code represents an error, a
3500-
non-zero local stop-sending, or a connection error still fails. A truncation
3499+
the stream. A peer reset or local stop-sending with an application code that
3500+
represents an error, or a connection error, still fails, but a truncation
35013501
with no error at all (an idle timeout, a graceful close, or a plain
35023502
`stopSending()`) ends the read cleanly with the data received. This matches
35033503
`stream.closed`, which rejects only on an error.

‎lib/internal/quic/quic.js‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1617,6 +1617,7 @@ class QuicStream {
16171617
pendingClose: undefined,
16181618
destroyError: undefined,
16191619
stopSendingCode: undefined,
1620+
stopSendingCodeIsError: undefined,
16201621
truncatedReads: undefined,
16211622
reader: undefined,
16221623
destroying: false,
@@ -1729,7 +1730,7 @@ class QuicStream {
17291730

17301731
// If we cancelled ourselves, check our own stop-sending code (not the
17311732
// result mirrored by the remote peer)
1732-
if (inner.stopSendingCode > 0n) {
1733+
if (inner.stopSendingCodeIsError) {
17331734
throw new QuicError('Stream aborted before FIN was received',
17341735
{ __proto__: null,
17351736
errorCode: inner.stopSendingCode });
@@ -2589,7 +2590,7 @@ class QuicStream {
25892590
if (this.destroyed) return;
25902591
const abortCode = validateQuicErrorCode(code, 'code');
25912592
this.#inner.stopSendingCode = abortCode;
2592-
this.#handle.stopSending(abortCode);
2593+
this.#inner.stopSendingCodeIsError = this.#handle.stopSending(abortCode);
25932594
}
25942595

25952596
/**

‎src/quic/application.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class Session::Application : public MemoryRetainer {
6060
// and is not necessarily 0.
6161
virtual error_code GetNoErrorCode() const = 0;
6262

63-
// Returns whether a received application error code means "no error".
63+
// Returns whether an application error code means "no error".
6464
// Applications may override this when unknown codes have special semantics.
6565
virtual bool IsNoErrorCode(error_code code) const {
6666
return code == GetNoErrorCode();

‎src/quic/streams.cc‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,8 +438,12 @@ struct Stream::Impl {
438438
ASSIGN_OR_RETURN_UNWRAP(&stream, args.This());
439439
CHECK(args[0]->IsBigInt());
440440
error_code code = args[0].As<BigInt>()->Uint64Value();
441+
const auto error = QuicError::ForApplication(code);
442+
const bool is_error = !stream->session().IsNoError(error);
441443

442444
stream->SendStopSending(code);
445+
446+
args.GetReturnValue().Set(is_error);
443447
}
444448

445449
// Sends a reset stream to the peer to tell it we will not be sending any

‎test/parallel/test-quic-h3-error-codes.mjs‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,3 +165,40 @@ const decoder = new TextDecoder();
165165
await clientSession.close();
166166
await serverEndpoint.close();
167167
}
168+
169+
// A locally sent STOP_SENDING with H3_NO_ERROR is a clean application-level
170+
// truncation. With truncatedReads: 'ignore', the nonzero code does not fail
171+
// the read.
172+
{
173+
const H3_NO_ERROR = 0x100n;
174+
175+
const serverEndpoint = await listen(mustCall(), {
176+
sni: { '*': { keys: [key], certs: [cert] } },
177+
onheaders: mustCall(),
178+
});
179+
180+
const clientSession = await connect(serverEndpoint.address, {
181+
servername: 'localhost',
182+
verifyPeer: 'manual',
183+
truncatedReads: 'ignore',
184+
});
185+
await clientSession.opened;
186+
187+
const stream = await clientSession.createBidirectionalStream({
188+
headers: {
189+
':method': 'GET',
190+
':path': '/',
191+
':scheme': 'https',
192+
':authority': 'localhost',
193+
},
194+
});
195+
stream.writer.endSync();
196+
197+
stream.stopSending(H3_NO_ERROR);
198+
const body = await bytes(stream);
199+
assert.strictEqual(body.byteLength, 0);
200+
await stream.closed;
201+
202+
await clientSession.close();
203+
await serverEndpoint.close();
204+
}

0 commit comments

Comments
 (0)