From b410d75091d78b67571fc74e33c016af6bc61bb2 Mon Sep 17 00:00:00 2001 From: Simone Bordet Date: Tue, 7 May 2019 16:22:44 +0200 Subject: [PATCH] Fixes #3605 - IdleTimeout with Jetty HTTP/2 and InputStreamResponseListener. Now properly resetting HttpReceiverOverHTTP2.ContentNotifier by overriding reset() and making sure fields are cleared from previous values. Also, disable channel recycling by default - needs to be benchmarked whether it's beneficial or not. Signed-off-by: Simone Bordet --- .../client/http/HttpConnectionOverHTTP2.java | 13 ++++++++- .../client/http/HttpReceiverOverHTTP2.java | 29 ++++++++++--------- 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/jetty-http2/http2-http-client-transport/src/main/java/org/eclipse/jetty/http2/client/http/HttpConnectionOverHTTP2.java b/jetty-http2/http2-http-client-transport/src/main/java/org/eclipse/jetty/http2/client/http/HttpConnectionOverHTTP2.java index 31e415ebce7..2d8b7bbc0cb 100644 --- a/jetty-http2/http2-http-client-transport/src/main/java/org/eclipse/jetty/http2/client/http/HttpConnectionOverHTTP2.java +++ b/jetty-http2/http2-http-client-transport/src/main/java/org/eclipse/jetty/http2/client/http/HttpConnectionOverHTTP2.java @@ -51,6 +51,7 @@ public class HttpConnectionOverHTTP2 extends HttpConnection implements Sweeper.S private final AtomicBoolean closed = new AtomicBoolean(); private final AtomicInteger sweeps = new AtomicInteger(); private final Session session; + private boolean recycleHttpChannels; public HttpConnectionOverHTTP2(HttpDestination destination, Session session) { @@ -63,6 +64,16 @@ public class HttpConnectionOverHTTP2 extends HttpConnection implements Sweeper.S return session; } + public boolean isRecycleHttpChannels() + { + return recycleHttpChannels; + } + + public void setRecycleHttpChannels(boolean recycleHttpChannels) + { + this.recycleHttpChannels = recycleHttpChannels; + } + @Override protected SendFailure send(HttpExchange exchange) { @@ -99,7 +110,7 @@ public class HttpConnectionOverHTTP2 extends HttpConnection implements Sweeper.S // Recycle only non-failed channels. if (channel.isFailed()) channel.destroy(); - else + else if (isRecycleHttpChannels()) idleChannels.offer(channel); } else diff --git a/jetty-http2/http2-http-client-transport/src/main/java/org/eclipse/jetty/http2/client/http/HttpReceiverOverHTTP2.java b/jetty-http2/http2-http-client-transport/src/main/java/org/eclipse/jetty/http2/client/http/HttpReceiverOverHTTP2.java index e4cde5c10c5..0d91d5ea4e3 100644 --- a/jetty-http2/http2-http-client-transport/src/main/java/org/eclipse/jetty/http2/client/http/HttpReceiverOverHTTP2.java +++ b/jetty-http2/http2-http-client-transport/src/main/java/org/eclipse/jetty/http2/client/http/HttpReceiverOverHTTP2.java @@ -213,21 +213,21 @@ public class HttpReceiverOverHTTP2 extends HttpReceiver implements Stream.Listen @Override protected Action process() { - DataInfo dataInfo; + if (dataInfo != null) + { + dataInfo.callback.succeeded(); + if (dataInfo.frame.isEndStream()) + return Action.SUCCEEDED; + } + synchronized (this) { dataInfo = queue.poll(); } if (dataInfo == null) - { - DataInfo prevDataInfo = this.dataInfo; - if (prevDataInfo != null && prevDataInfo.frame.isEndStream()) - return Action.SUCCEEDED; return Action.IDLE; - } - this.dataInfo = dataInfo; ByteBuffer buffer = dataInfo.frame.getData(); if (buffer.hasRemaining()) responseContent(dataInfo.exchange, buffer, this); @@ -244,13 +244,6 @@ public class HttpReceiverOverHTTP2 extends HttpReceiver implements Stream.Listen ((Retainable)callback).retain(); } - @Override - public void succeeded() - { - dataInfo.callback.succeeded(); - super.succeeded(); - } - @Override protected void onCompleteSuccess() { @@ -263,6 +256,14 @@ public class HttpReceiverOverHTTP2 extends HttpReceiver implements Stream.Listen dataInfo.callback.failed(failure); responseFailure(failure); } + + @Override + public boolean reset() + { + queue.clear(); + dataInfo = null; + return super.reset(); + } } private static class DataInfo