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 78d9548ae6c..30ccfc75de9 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 @@ -38,6 +38,7 @@ import org.eclipse.jetty.http2.frames.ResetFrame; import org.eclipse.jetty.io.ByteBufferPool; import org.eclipse.jetty.util.BufferUtil; import org.eclipse.jetty.util.Callback; +import org.eclipse.jetty.util.CompletableCallback; public class HttpReceiverOverHTTP2 extends HttpReceiver implements Stream.Listener { @@ -110,26 +111,40 @@ public class HttpReceiverOverHTTP2 extends HttpReceiver implements Stream.Listen copy.put(original); BufferUtil.flipToFlush(copy, 0); - Callback delegate = new Callback.Nested(callback) + CompletableCallback delegate = new CompletableCallback() { @Override public void succeeded() { byteBufferPool.release(copy); + callback.succeeded(); super.succeeded(); - if (frame.isEndStream()) - responseSuccess(exchange); } @Override public void failed(Throwable x) { byteBufferPool.release(copy); + callback.failed(x); super.failed(x); } + + @Override + public void resume() + { + if (frame.isEndStream()) + responseSuccess(exchange); + } + + @Override + public void abort(Throwable failure) + { + } }; responseContent(exchange, copy, delegate); + if (!delegate.tryComplete()) + delegate.resume(); } @Override diff --git a/tests/test-http-client-transport/src/test/java/org/eclipse/jetty/http/client/HttpClientTest.java b/tests/test-http-client-transport/src/test/java/org/eclipse/jetty/http/client/HttpClientTest.java index 2e7bd8ffc69..0dd9d17e8b9 100644 --- a/tests/test-http-client-transport/src/test/java/org/eclipse/jetty/http/client/HttpClientTest.java +++ b/tests/test-http-client-transport/src/test/java/org/eclipse/jetty/http/client/HttpClientTest.java @@ -408,6 +408,8 @@ public class HttpClientTest extends AbstractTest InputStream input = listener.getInputStream(); Assert.assertEquals(content, IO.toString(input)); + + Assert.assertTrue(latch.await(5, TimeUnit.SECONDS)); } private void sleep(long time) throws IOException