diff --git a/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/HTTP2Session.java b/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/HTTP2Session.java index fb3a8e1f46a..015507ecdb6 100644 --- a/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/HTTP2Session.java +++ b/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/HTTP2Session.java @@ -278,7 +278,7 @@ public abstract class HTTP2Session extends ContainerLifeCycle implements ISessio // otherwise other requests will be stalled. flowControl.onDataConsumed(this, null, flowControlLength); if (isStreamClosed(streamId)) - reset(new ResetFrame(streamId, ErrorCode.STREAM_CLOSED_ERROR.code), callback); + reset(null, new ResetFrame(streamId, ErrorCode.STREAM_CLOSED_ERROR.code), callback); else onConnectionFailure(ErrorCode.PROTOCOL_ERROR.code, "unexpected_data_frame", callback); } @@ -505,7 +505,7 @@ public abstract class HTTP2Session extends ContainerLifeCycle implements ISessio int streamSendWindow = stream.updateSendWindow(0); if (MathUtils.sumOverflows(streamSendWindow, windowDelta)) { - reset(new ResetFrame(streamId, ErrorCode.FLOW_CONTROL_ERROR.code), Callback.NOOP); + reset(stream, new ResetFrame(streamId, ErrorCode.FLOW_CONTROL_ERROR.code), Callback.NOOP); } else { @@ -642,9 +642,16 @@ public abstract class HTTP2Session extends ContainerLifeCycle implements ISessio control(null, callback, frame); } - protected void reset(ResetFrame frame, Callback callback) + void reset(IStream stream, ResetFrame frame, Callback callback) { - control(getStream(frame.getStreamId()), callback, frame); + control(stream, Callback.from(() -> + { + if (stream != null) + { + stream.close(); + removeStream(stream); + } + }, callback), frame); } /** @@ -810,7 +817,7 @@ public abstract class HTTP2Session extends ContainerLifeCycle implements ISessio if (maxCount >= 0 && remoteCount - remoteClosing >= maxCount) { updateLastRemoteStreamId(streamId); - reset(new ResetFrame(streamId, ErrorCode.REFUSED_STREAM_ERROR.code), Callback.NOOP); + reset(null, new ResetFrame(streamId, ErrorCode.REFUSED_STREAM_ERROR.code), Callback.NOOP); return null; } if (remoteStreamCount.compareAndSet(encoded, remoteCount + 1, remoteClosing)) @@ -1331,15 +1338,6 @@ public abstract class HTTP2Session extends ContainerLifeCycle implements ISessio removeStream(stream); break; } - case RST_STREAM: - { - if (stream != null) - { - stream.close(); - removeStream(stream); - } - break; - } case PUSH_PROMISE: { // Pushed streams are implicitly remotely closed. @@ -1568,7 +1566,7 @@ public abstract class HTTP2Session extends ContainerLifeCycle implements ISessio private void complete() { - reset(new ResetFrame(streamId, error), getCallback()); + reset(getStream(streamId), new ResetFrame(streamId, error), getCallback()); } } diff --git a/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/HTTP2Stream.java b/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/HTTP2Stream.java index b00d4ca87ed..d0b108230ff 100644 --- a/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/HTTP2Stream.java +++ b/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/HTTP2Stream.java @@ -21,7 +21,6 @@ package org.eclipse.jetty.http2; import java.io.EOFException; import java.io.IOException; import java.nio.channels.WritePendingException; -import java.util.Collections; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.TimeUnit; @@ -144,7 +143,7 @@ public class HTTP2Stream extends IdleTimeout implements IStream, Callback, Dumpa localReset = true; failure = new EOFException("reset"); } - session.frames(this, Collections.singletonList(frame), callback); + ((HTTP2Session)session).reset(this, frame, callback); } private boolean startWrite(Callback callback)