Skip to content

Commit

Permalink
fix to send a goaway if should disconnect
Browse files Browse the repository at this point in the history
  • Loading branch information
jrhee17 committed Nov 7, 2021
1 parent 8018da1 commit d1183d8
Showing 1 changed file with 14 additions and 22 deletions.
Expand Up @@ -139,16 +139,18 @@ public void onStreamClosed(Http2Stream stream) {
return;
}

if (!goAwayHandler.receivedGoAway()) {
res.close(ClosedStreamException.get());
return;
}
if (res.isOpen()) {
if (!goAwayHandler.receivedGoAway()) {
res.close(ClosedStreamException.get());
return;
}

final int lastStreamId = conn.local().lastStreamKnownByPeer();
if (stream.id() > lastStreamId) {
res.close(UnprocessedRequestException.of(GoAwayReceivedException.get()));
} else {
res.close(ClosedStreamException.get());
final int lastStreamId = conn.local().lastStreamKnownByPeer();
if (stream.id() > lastStreamId) {
res.close(UnprocessedRequestException.of(GoAwayReceivedException.get()));
} else {
res.close(ClosedStreamException.get());
}
}

if (shouldSendGoAway()) {
Expand Down Expand Up @@ -185,7 +187,7 @@ public void onSettingsAckRead(ChannelHandlerContext ctx) {}
public void onHeadersRead(ChannelHandlerContext ctx, int streamId, Http2Headers headers, int padding,
boolean endOfStream) throws Http2Exception {
keepAliveChannelRead();
final HttpResponseWrapper res = getResponse(streamIdToId(streamId), endOfStream);
final HttpResponseWrapper res = getResponse(streamIdToId(streamId));
if (res == null || !res.isOpen()) {
if (conn.streamMayHaveExisted(streamId)) {
if (logger.isDebugEnabled()) {
Expand All @@ -212,10 +214,6 @@ public void onHeadersRead(ChannelHandlerContext ctx, int streamId, Http2Headers

if (endOfStream) {
res.close();

if (shouldSendGoAway()) {
channel().close();
}
}
}

Expand All @@ -234,7 +232,7 @@ public int onDataRead(
keepAliveChannelRead();

final int dataLength = data.readableBytes();
final HttpResponseWrapper res = getResponse(streamIdToId(streamId), endOfStream);
final HttpResponseWrapper res = getResponse(streamIdToId(streamId));
if (res == null || !res.isOpen()) {
if (conn.streamMayHaveExisted(streamId)) {
if (logger.isDebugEnabled()) {
Expand Down Expand Up @@ -272,12 +270,6 @@ public int onDataRead(

if (endOfStream) {
res.close();

if (shouldSendGoAway()) {
// The connection has reached its lifespan.
// Should send a GOAWAY frame if it did not receive or send a GOAWAY frame.
channel().close();
}
}

// All bytes have been processed.
Expand All @@ -295,7 +287,7 @@ private boolean shouldSendGoAway() {
@Override
public void onRstStreamRead(ChannelHandlerContext ctx, int streamId, long errorCode) throws Http2Exception {
keepAliveChannelRead();
final HttpResponseWrapper res = removeResponse(streamIdToId(streamId));
final HttpResponseWrapper res = getResponse(streamIdToId(streamId));
if (res == null || !res.isOpen()) {
if (conn.streamMayHaveExisted(streamId)) {
if (logger.isDebugEnabled()) {
Expand Down

0 comments on commit d1183d8

Please sign in to comment.