From 09d54eacabfdae5499564a20c451b4162442ccfc Mon Sep 17 00:00:00 2001 From: Simone Bordet Date: Tue, 19 Aug 2014 13:38:43 +0200 Subject: [PATCH] Accounting for the session flow control window in case of reset streams. --- .../java/org/eclipse/jetty/http2/FlowControl.java | 2 +- .../org/eclipse/jetty/http2/HTTP2FlowControl.java | 12 +++++++----- .../java/org/eclipse/jetty/http2/HTTP2Session.java | 11 +++++++---- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/FlowControl.java b/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/FlowControl.java index 1126f74b324..e87aa3d8533 100644 --- a/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/FlowControl.java +++ b/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/FlowControl.java @@ -30,7 +30,7 @@ public interface FlowControl public void onWindowUpdate(ISession session, IStream stream, WindowUpdateFrame frame); - public void onDataReceived(IStream stream, int length); + public void onDataReceived(ISession session, IStream stream, int length); public void onDataConsumed(IStream stream, int length); diff --git a/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/HTTP2FlowControl.java b/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/HTTP2FlowControl.java index dd426fb876b..937fe1e2059 100644 --- a/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/HTTP2FlowControl.java +++ b/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/HTTP2FlowControl.java @@ -78,16 +78,18 @@ public class HTTP2FlowControl implements FlowControl } @Override - public void onDataReceived(IStream stream, int length) + public void onDataReceived(ISession session, IStream stream, int length) { - ISession session = stream.getSession(); int oldSize = session.updateRecvWindow(-length); if (LOG.isDebugEnabled()) LOG.debug("Updated session recv window {} -> {} for {}", oldSize, oldSize - length, session); - oldSize = stream.updateRecvWindow(-length); - if (LOG.isDebugEnabled()) - LOG.debug("Updated stream recv window {} -> {} for {}", oldSize, oldSize - length, stream); + if (stream != null) + { + oldSize = stream.updateRecvWindow(-length); + if (LOG.isDebugEnabled()) + LOG.debug("Updated stream recv window {} -> {} for {}", oldSize, oldSize - length, stream); + } } @Override 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 a400370c9c9..5e510372a39 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 @@ -129,16 +129,19 @@ public abstract class HTTP2Session implements ISession, Parser.Listener { if (LOG.isDebugEnabled()) LOG.debug("Received {}", frame); + int streamId = frame.getStreamId(); final IStream stream = getStream(streamId); + + // SPEC: the session window must be updated even if the stream is null. + // The flow control length includes the padding bytes. + final int flowControlLength = frame.remaining() + frame.padding(); + flowControl.onDataReceived(this, stream, flowControlLength); + if (stream != null) { stream.updateClose(frame.isEndStream(), false); - // The flow control length includes the padding bytes. - final int flowControlLength = frame.remaining() + frame.padding(); - flowControl.onDataReceived(stream, flowControlLength); - if (getRecvWindow() < 0) { close(ErrorCodes.FLOW_CONTROL_ERROR, "session_window_exceeded", disconnectOnFailure);