Skip to content

Commit 7cb9fd4

Browse files
committed
fix: cleaned fix for concurrent cancellation
1 parent 6fb7e24 commit 7cb9fd4

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/QUICConnection.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -911,13 +911,21 @@ class QUICConnection extends EventTarget {
911911
// There is one condition where this can happen. That is when both sides of the stream cancel concurrently.
912912
// Local state is cleaned up while the remote side still sends a closing frame.
913913
try {
914+
// Check if the stream can write 0 bytes, should throw if the stream has ended.
915+
// We need to check if it's writable to trigger any state change for the stream.
914916
this.conn.streamWritable(streamId, 0);
915-
this.logger.debug(
916-
`streamId ${streamId} was writable without an existing stream`,
917+
never(
918+
'The stream should never be writable if a QUICStream does not exist for it',
917919
);
918920
} catch (e) {
921+
// Stream should be stopped here, any other error is a never
922+
if (e.message.match(/StreamStopped\((.+)\)/) == null) {
923+
// We only expect a StreamStopped error here
924+
throw e;
925+
}
926+
// If stopped we just ignore it, `streamWritable` should've cleaned up the native state
919927
this.logger.debug(
920-
`streamId ${streamId} was writable without an existing stream and error ${e.message}`,
928+
`StreamId ${streamId} was writable without an existing stream and error ${e.message}`,
921929
);
922930
}
923931
} else {

0 commit comments

Comments
 (0)