Fixes #2291 - Expose HTTP/2 close reason in dumps.

Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
This commit is contained in:
Simone Bordet 2018-03-07 00:45:23 +01:00
parent 8fcfdd9d7f
commit 5dea9b673e
2 changed files with 21 additions and 9 deletions

View File

@ -89,6 +89,7 @@ public abstract class HTTP2Session extends ContainerLifeCycle implements ISessio
private int initialSessionRecvWindow;
private boolean pushEnabled;
private long idleTime;
private GoAwayFrame closeFrame;
public HTTP2Session(Scheduler scheduler, EndPoint endPoint, Generator generator, Session.Listener listener, FlowControlStrategy flowControl, int initialStreamId)
{
@ -430,6 +431,7 @@ public abstract class HTTP2Session extends ContainerLifeCycle implements ISessio
{
// We received a GO_AWAY, so try to write
// what's in the queue and then disconnect.
closeFrame = frame;
notifyClose(this, frame, new DisconnectCallback());
return;
}
@ -597,8 +599,8 @@ public abstract class HTTP2Session extends ContainerLifeCycle implements ISessio
{
if (closed.compareAndSet(current, CloseState.LOCALLY_CLOSED))
{
GoAwayFrame frame = newGoAwayFrame(error, reason);
control(null, callback, frame);
closeFrame = newGoAwayFrame(CloseState.LOCALLY_CLOSED, error, reason);
control(null, callback, closeFrame);
return true;
}
break;
@ -614,7 +616,7 @@ public abstract class HTTP2Session extends ContainerLifeCycle implements ISessio
}
}
private GoAwayFrame newGoAwayFrame(int error, String reason)
private GoAwayFrame newGoAwayFrame(CloseState closeState, int error, String reason)
{
byte[] payload = null;
if (reason != null)
@ -623,7 +625,7 @@ public abstract class HTTP2Session extends ContainerLifeCycle implements ISessio
reason = reason.substring(0, Math.min(reason.length(), 32));
payload = reason.getBytes(StandardCharsets.UTF_8);
}
return new GoAwayFrame(lastStreamId.get(), error, payload);
return new GoAwayFrame(closeState, lastStreamId.get(), error, payload);
}
@Override
@ -1125,7 +1127,7 @@ public abstract class HTTP2Session extends ContainerLifeCycle implements ISessio
@Override
public String toString()
{
return String.format("%s@%x{l:%s <-> r:%s,sendWindow=%s,recvWindow=%s,streams=%d,%s}",
return String.format("%s@%x{l:%s <-> r:%s,sendWindow=%s,recvWindow=%s,streams=%d,%s,%s}",
getClass().getSimpleName(),
hashCode(),
getEndPoint().getLocalAddress(),
@ -1133,7 +1135,8 @@ public abstract class HTTP2Session extends ContainerLifeCycle implements ISessio
sendWindow,
recvWindow,
streams.size(),
closed);
closed,
closeFrame);
}
private class ControlEntry extends HTTP2Flusher.Entry
@ -1453,7 +1456,7 @@ public abstract class HTTP2Session extends ContainerLifeCycle implements ISessio
private void complete()
{
frames(null, Callback.NOOP, newGoAwayFrame(ErrorCode.NO_ERROR.code, null), new DisconnectFrame());
frames(null, Callback.NOOP, newGoAwayFrame(CloseState.CLOSED, ErrorCode.NO_ERROR.code, null), new DisconnectFrame());
}
}

View File

@ -20,17 +20,25 @@ package org.eclipse.jetty.http2.frames;
import java.nio.charset.StandardCharsets;
import org.eclipse.jetty.http2.CloseState;
import org.eclipse.jetty.http2.ErrorCode;
public class GoAwayFrame extends Frame
{
private final CloseState closeState;
private final int lastStreamId;
private final int error;
private final byte[] payload;
public GoAwayFrame(int lastStreamId, int error, byte[] payload)
{
this(CloseState.REMOTELY_CLOSED, lastStreamId, error, payload);
}
public GoAwayFrame(CloseState closeState, int lastStreamId, int error, byte[] payload)
{
super(FrameType.GO_AWAY);
this.closeState = closeState;
this.lastStreamId = lastStreamId;
this.error = error;
this.payload = payload;
@ -69,10 +77,11 @@ public class GoAwayFrame extends Frame
public String toString()
{
ErrorCode errorCode = ErrorCode.from(error);
return String.format("%s,%d/%s/%s",
return String.format("%s,%d/%s/%s/%s",
super.toString(),
lastStreamId,
errorCode != null ? errorCode.toString() : String.valueOf(error),
tryConvertPayload());
tryConvertPayload(),
closeState);
}
}