Skip to content

Commit 32d1158

Browse files
authored
Cleanup code to make stacktrace less confusing (#796)
Motivation: 5dade1f introduced a change that did prevent the Channel to be closed if a STREAM_STOPPED frame was received but did not change the name of the method from forceClose(...) to something else. This makes the stacktrace quite confusing as while the method is called forceClose(...) it actually might not close the channel. Modifications: - Move all the logic into the writable(...) method and so make things less confusing Result: Less confusing stacktrace for failed writes
1 parent d03b508 commit 32d1158

File tree

2 files changed

+23
-31
lines changed

2 files changed

+23
-31
lines changed

codec-classes-quic/src/main/java/io/netty/incubator/codec/quic/QuicheQuicChannel.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,10 +1087,7 @@ private boolean handleWritableStreams(QuicheQuicConnection conn) {
10871087
QuicheQuicStreamChannel streamChannel = streams.get(streamId);
10881088
if (streamChannel != null) {
10891089
int capacity = Quiche.quiche_conn_stream_capacity(connAddr, streamId);
1090-
if (capacity < 0) {
1091-
// Let's close the channel if quiche_conn_stream_capacity(...) returns an error.
1092-
streamChannel.forceClose(capacity);
1093-
} else if (streamChannel.writable(capacity)) {
1090+
if (streamChannel.writable(capacity)) {
10941091
mayNeedWrite = true;
10951092
}
10961093
}

codec-classes-quic/src/main/java/io/netty/incubator/codec/quic/QuicheQuicStreamChannel.java

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -410,10 +410,31 @@ public String toString() {
410410
}
411411

412412
/**
413-
* Stream is writable.
413+
* Stream writability changed.
414414
*/
415415
boolean writable(int capacity) {
416416
assert eventLoop().inEventLoop();
417+
if (capacity < 0) {
418+
// If the value is negative its a quiche error.
419+
if (capacity != Quiche.QUICHE_ERR_DONE) {
420+
if (!queue.isEmpty()) {
421+
if (capacity == Quiche.QUICHE_ERR_STREAM_STOPPED) {
422+
queue.removeAndFailAll(new ChannelOutputShutdownException("STOP_SENDING frame received"));
423+
// If STOP_SENDING is received we should not close the channel but just fail all queued writes.
424+
return false;
425+
} else {
426+
queue.removeAndFailAll(Quiche.convertToException(capacity));
427+
}
428+
} else if (capacity == Quiche.QUICHE_ERR_STREAM_STOPPED) {
429+
// If STOP_SENDING is received we should not close the channel
430+
return false;
431+
}
432+
// IF this error was not QUICHE_ERR_STREAM_STOPPED we should close the channel.
433+
finSent = true;
434+
unsafe().close(unsafe().voidPromise());
435+
}
436+
return false;
437+
}
417438
this.capacity = capacity;
418439
boolean mayNeedWrite = unsafe().writeQueued();
419440
// we need to re-read this.capacity as writeQueued() may update the capacity.
@@ -428,25 +449,6 @@ private void updateWritabilityIfNeeded(boolean newWritable) {
428449
}
429450
}
430451

431-
void forceClose(int error) {
432-
if (error == Quiche.QUICHE_ERR_DONE) {
433-
return;
434-
}
435-
if (!queue.isEmpty()) {
436-
if (error == Quiche.QUICHE_ERR_STREAM_STOPPED) {
437-
queue.removeAndFailAll(new ChannelOutputShutdownException("STOP_SENDING frame received"));
438-
// If STOP_SENDING is received we should not close the channel but just fail all queued writes.
439-
return;
440-
} else {
441-
queue.removeAndFailAll(Quiche.convertToException(error));
442-
}
443-
} else if (error == Quiche.QUICHE_ERR_STREAM_STOPPED) {
444-
// If STOP_SENDING is received we should not close the channel
445-
return;
446-
}
447-
forceClose();
448-
}
449-
450452
/**
451453
* Stream is readable.
452454
*/
@@ -459,13 +461,6 @@ void readable() {
459461
}
460462
}
461463

462-
void forceClose() {
463-
assert eventLoop().inEventLoop();
464-
// Set received to true to ensure we will remove it from the internal map once we send the fin.
465-
finSent = true;
466-
unsafe().close(unsafe().voidPromise());
467-
}
468-
469464
final class QuicStreamChannelUnsafe implements Unsafe {
470465

471466
@SuppressWarnings("deprecation")

0 commit comments

Comments
 (0)