Skip to content

Commit

Permalink
Use ClosedSessionException and ClosedStreamException correctly (#4380)
Browse files Browse the repository at this point in the history
Motivation:
`ClosedStreamException` is raised when a {@link StreamMessage} or an HTTP/2 stream
has been closed unexpectedly. Whereas, `ClosedSessionException` is raised
when the connection to the remote peer has been closed unexpectedly.

Modifications:
- Use `ClosedSessionException` and `ClosedStreamException` correctly according to its usage.

Result:
- `ClosedSessionException` and `ClosedStreamException` are raised correctly according to its usage.
  • Loading branch information
minwoox authored Aug 4, 2022
1 parent dd31525 commit 03645e9
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import com.linecorp.armeria.common.HttpData;
import com.linecorp.armeria.common.ProtocolViolationException;
import com.linecorp.armeria.common.annotation.Nullable;
import com.linecorp.armeria.common.stream.ClosedStreamException;
import com.linecorp.armeria.internal.common.ArmeriaHttpUtil;
import com.linecorp.armeria.internal.common.InboundTrafficController;
import com.linecorp.armeria.internal.common.KeepAliveHandler;
Expand Down Expand Up @@ -184,7 +183,7 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception

res.initTimeout();
if (!res.tryWrite(ArmeriaHttpUtil.toArmeria(nettyRes))) {
fail(ctx, ClosedStreamException.get());
fail(ctx, ClosedSessionException.get());
return;
}
} else {
Expand Down Expand Up @@ -222,7 +221,7 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception
.build());
return;
} else if (!res.tryWrite(HttpData.wrap(data.retain()))) {
fail(ctx, ClosedStreamException.get());
fail(ctx, ClosedSessionException.get());
return;
}
}
Expand All @@ -238,7 +237,7 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception
final HttpHeaders trailingHeaders = ((LastHttpContent) msg).trailingHeaders();
if (!trailingHeaders.isEmpty() &&
!res.tryWrite(ArmeriaHttpUtil.toArmeria(trailingHeaders))) {
fail(ctx, ClosedStreamException.get());
fail(ctx, ClosedSessionException.get());
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
import com.linecorp.armeria.common.annotation.Nullable;

/**
* A {@link RuntimeException} that is raised when a {@link StreamMessage} has been closed unexpectedly.
* A {@link RuntimeException} that is raised when a {@link StreamMessage} or an HTTP/2 stream
* has been closed unexpectedly.
*/
public class ClosedStreamException extends RuntimeException {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import com.linecorp.armeria.common.HttpData;
import com.linecorp.armeria.common.HttpHeaders;
import com.linecorp.armeria.common.SessionProtocol;
import com.linecorp.armeria.common.stream.ClosedStreamException;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
Expand Down Expand Up @@ -251,7 +250,7 @@ final ChannelFuture write(int id, HttpObject obj, boolean endStream, ChannelProm
// Attempted to write something on a finished request/response; discard.
// e.g. the request already timed out.
ReferenceCountUtil.release(obj);
promise.setFailure(ClosedStreamException.get());
promise.setFailure(ClosedSessionException.get());
return promise;
}

Expand Down Expand Up @@ -351,7 +350,7 @@ public final ChannelFuture doWriteReset(int id, int streamId, Http2Error error)

if (minClosedId <= maxIdWithPendingWrites) {
final ClosedSessionException cause =
new ClosedSessionException("An HTTP/1 stream has been reset: " + error);
new ClosedSessionException("An HTTP/1 connection has been reset: " + error);
for (int i = minClosedId; i <= maxIdWithPendingWrites; i++) {
final PendingWrites pendingWrites = pendingWritesMap.remove(i);
for (;;) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ final boolean failIfStreamOrSessionClosed() {
Throwable cause = CapturedServiceException.get(reqCtx);
if (cause == null) {
if (reqCtx.sessionProtocol().isMultiplex()) {
cause = ClosedSessionException.get();
} else {
cause = ClosedStreamException.get();
} else {
cause = ClosedSessionException.get();
}
}
fail(cause);
Expand Down

0 comments on commit 03645e9

Please sign in to comment.