Skip to content

Commit

Permalink
Fail writes with ChannelOutputShutdownException when STREAM_STOPPED i… (
Browse files Browse the repository at this point in the history
java-native-access#683)

…s received

Motivation:

If STREAM_STOPPED is received we should fail all writes with
ChannelOutputShutdownException before tearing down the channel

Modifications:

Explicit handle STREAM_STOPPED

Result:

Better signaling of received STREAM_STOPPED
  • Loading branch information
normanmaurer authored Mar 4, 2024
1 parent e78fdb1 commit a7b3ba7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1063,7 +1063,7 @@ private boolean handleWritableStreams(QuicheQuicConnection conn) {
int capacity = Quiche.quiche_conn_stream_capacity(connAddr, streamId);
if (capacity < 0) {
// Let's close the channel if quiche_conn_stream_capacity(...) returns an error.
streamChannel.forceClose();
streamChannel.forceClose(capacity);
} else if (streamChannel.writable(capacity)) {
mayNeedWrite = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,18 @@ private void updateWritabilityIfNeeded(boolean newWritable) {
}
}

void forceClose(int error) {
if (!queue.isEmpty()) {
QuicException err = new QuicException(QuicError.valueOf(error));
if (error == QuicError.STREAM_STOPPED.code()) {
queue.removeAndFailAll(new ChannelOutputShutdownException("STREAM_STOPPED received", err));
} else {
queue.removeAndFailAll(err);
}
}
forceClose();
}

/**
* Stream is readable.
*/
Expand Down Expand Up @@ -646,7 +658,9 @@ boolean writeQueued() {
if (e instanceof QuicException && (
(QuicException) e).error() == QuicError.STREAM_STOPPED) {
// Once its signaled that the stream is stopped we can just fail everything.
queue.removeAndFailAll(e);
// We can also force the close as quiche will generate a RESET_STREAM frame.
queue.removeAndFailAll(
new ChannelOutputShutdownException("STREAM_STOPPED received", e));
forceClose();
break;
}
Expand Down

0 comments on commit a7b3ba7

Please sign in to comment.