Skip to content

Commit bcd557b

Browse files
committed
fix: using reasonToCode instead of using hard coded shutdown codes for streams
* Related: #77 [ci skip]
1 parent 63e7c41 commit bcd557b

File tree

3 files changed

+37
-8
lines changed

3 files changed

+37
-8
lines changed

src/QUICConnection.ts

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -542,10 +542,18 @@ class QUICConnection {
542542
// No `QUICStream` objects could have been created, however quiche stream
543543
// state should be cleaned up, and this can be done synchronously
544544
for (const streamId of this.conn.readable() as Iterable<StreamId>) {
545-
this.conn.streamShutdown(streamId, quiche.Shutdown.Read, 0);
545+
this.conn.streamShutdown(
546+
streamId,
547+
quiche.Shutdown.Read,
548+
this.reasonToCode('read', e),
549+
);
546550
}
547551
for (const streamId of this.conn.writable() as Iterable<StreamId>) {
548-
this.conn.streamShutdown(streamId, quiche.Shutdown.Write, 0);
552+
this.conn.streamShutdown(
553+
streamId,
554+
quiche.Shutdown.Write,
555+
this.reasonToCode('write', e),
556+
);
549557
}
550558
// According to RFC9000, closing while in the middle of a handshake
551559
// should use a transport error code `APPLICATION_ERROR`.
@@ -954,8 +962,16 @@ class QUICConnection {
954962
if (quicStream == null) {
955963
if (this[running] === false || this[status] === 'stopping') {
956964
// We should reject new connections when stopping
957-
this.conn.streamShutdown(streamId, Shutdown.Write, 1);
958-
this.conn.streamShutdown(streamId, Shutdown.Read, 1);
965+
this.conn.streamShutdown(
966+
streamId,
967+
Shutdown.Write,
968+
this.reasonToCode('write', errors.ErrorQUICConnectionStopping),
969+
);
970+
this.conn.streamShutdown(
971+
streamId,
972+
Shutdown.Read,
973+
this.reasonToCode('read', errors.ErrorQUICConnectionStopping),
974+
);
959975
continue;
960976
}
961977

@@ -990,8 +1006,16 @@ class QUICConnection {
9901006
if (quicStream == null) {
9911007
if (this[running] === false || this[status] === 'stopping') {
9921008
// We should reject new connections when stopping
993-
this.conn.streamShutdown(streamId, Shutdown.Write, 1);
994-
this.conn.streamShutdown(streamId, Shutdown.Read, 1);
1009+
this.conn.streamShutdown(
1010+
streamId,
1011+
Shutdown.Write,
1012+
this.reasonToCode('write', errors.ErrorQUICConnectionStopping),
1013+
);
1014+
this.conn.streamShutdown(
1015+
streamId,
1016+
Shutdown.Read,
1017+
this.reasonToCode('read', errors.ErrorQUICConnectionStopping),
1018+
);
9951019
continue;
9961020
}
9971021

src/errors.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ class ErrorQUICConnection<T> extends ErrorQUIC<T> {
9292
static description = 'QUIC Connection error';
9393
}
9494

95+
class ErrorQUICConnectionStopping<T> extends ErrorQUICConnection<T> {
96+
static description = 'QUIC Connection is stopping';
97+
}
98+
9599
class ErrorQUICConnectionNotRunning<T> extends ErrorQUICConnection<T> {
96100
static description = 'QUIC Connection is not running';
97101
}
@@ -297,6 +301,7 @@ export {
297301
ErrorQUICServerNewConnection,
298302
ErrorQUICServerInternal,
299303
ErrorQUICConnection,
304+
ErrorQUICConnectionStopping,
300305
ErrorQUICConnectionNotRunning,
301306
ErrorQUICConnectionClosed,
302307
ErrorQUICConnectionStartData,

tests/QUICStream.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1487,12 +1487,12 @@ describe(QUICStream.name, () => {
14871487
// Creating a stream on the server side should throw
14881488
const newStream = conn.newStream();
14891489
await newStream.writable.close();
1490-
const asd = (async () => {
1490+
const code = (async () => {
14911491
for await (const _ of newStream.readable) {
14921492
// Do nothing
14931493
}
14941494
})();
1495-
await expect(asd).rejects.toThrow('read 1');
1495+
await expect(code).rejects.toThrow('read 0');
14961496

14971497
waitResolveP();
14981498
await Promise.all(activeServerStreams);

0 commit comments

Comments
 (0)