-
Notifications
You must be signed in to change notification settings - Fork 918
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add more debug information to HTTP/2 GOAWAY frame #145
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,12 +16,17 @@ | |
|
||
package com.linecorp.armeria.common.http; | ||
|
||
import static io.netty.handler.codec.http2.Http2Error.INTERNAL_ERROR; | ||
|
||
import com.linecorp.armeria.common.util.Exceptions; | ||
|
||
import io.netty.channel.ChannelHandlerContext; | ||
import io.netty.channel.ChannelPromise; | ||
import io.netty.handler.codec.http2.Http2ConnectionDecoder; | ||
import io.netty.handler.codec.http2.Http2ConnectionEncoder; | ||
import io.netty.handler.codec.http2.Http2ConnectionHandler; | ||
import io.netty.handler.codec.http2.Http2Exception; | ||
import io.netty.handler.codec.http2.Http2Exception.ClosedStreamCreationException; | ||
import io.netty.handler.codec.http2.Http2Settings; | ||
import io.netty.handler.codec.http2.Http2Stream.State; | ||
import io.netty.handler.codec.http2.Http2StreamVisitor; | ||
|
@@ -43,8 +48,10 @@ public abstract class AbstractHttpToHttp2ConnectionHandler extends HttpToHttp2Co | |
private boolean closing; | ||
private boolean handlingConnectionError; | ||
|
||
protected AbstractHttpToHttp2ConnectionHandler(Http2ConnectionDecoder decoder, Http2ConnectionEncoder encoder, | ||
Http2Settings initialSettings, boolean validateHeaders) { | ||
protected AbstractHttpToHttp2ConnectionHandler( | ||
Http2ConnectionDecoder decoder, Http2ConnectionEncoder encoder, | ||
Http2Settings initialSettings, boolean validateHeaders) { | ||
|
||
super(decoder, encoder, initialSettings, validateHeaders); | ||
} | ||
|
||
|
@@ -59,9 +66,45 @@ protected void onConnectionError(ChannelHandlerContext ctx, Throwable cause, Htt | |
} | ||
|
||
handlingConnectionError = true; | ||
|
||
// TODO(trustin): Remove this once Http2ConnectionHandler.goAway() sends better debugData. | ||
// See https://github.com/netty/netty/issues/5160 | ||
if (http2Ex == null) { | ||
http2Ex = new Http2Exception(INTERNAL_ERROR, goAwayDebugData(null, cause), cause); | ||
} else if (http2Ex instanceof ClosedStreamCreationException) { | ||
final ClosedStreamCreationException e = (ClosedStreamCreationException) http2Ex; | ||
http2Ex = new ClosedStreamCreationException(e.error(), goAwayDebugData(e, cause), cause); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mostly to clarify, is there a difference between cause and http2Ex.cause here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. They are same as far as I know. |
||
} else { | ||
http2Ex = new Http2Exception( | ||
http2Ex.error(), goAwayDebugData(http2Ex, cause), cause, http2Ex.shutdownHint()); | ||
} | ||
|
||
super.onConnectionError(ctx, cause, http2Ex); | ||
} | ||
|
||
private static String goAwayDebugData(Http2Exception http2Ex, Throwable cause) { | ||
final StringBuilder buf = new StringBuilder(256); | ||
final String type; | ||
final String message; | ||
|
||
if (http2Ex != null) { | ||
type = http2Ex.getClass().getName(); | ||
message = http2Ex.getMessage(); | ||
} else { | ||
type = null; | ||
message = null; | ||
} | ||
|
||
buf.append("type: "); | ||
buf.append(type != null ? type : "n/a"); | ||
buf.append(", message: "); | ||
buf.append(message != null ? message : "n/a"); | ||
buf.append(", cause: "); | ||
buf.append(cause != null ? Exceptions.traceText(cause) : "n/a"); | ||
|
||
return buf.toString(); | ||
} | ||
|
||
@Override | ||
public void close(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception { | ||
closing = true; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any upstream issue to reference?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea. Will add a link.