From 6aedfe52f104e4b825903983e2e993538174f33c Mon Sep 17 00:00:00 2001 From: Simone Bordet Date: Tue, 2 Nov 2021 16:51:03 +0100 Subject: [PATCH] Issue #6728 - QUIC and HTTP/3 - Fixed HttpChannelOverHTTP3 input reading. Signed-off-by: Simone Bordet --- .../server/internal/HttpChannelOverHTTP3.java | 82 ++++++++++--------- .../jetty/quic/quiche/QuicheConnection.java | 2 +- .../jetty/http/client/HttpClientLoadTest.java | 12 +-- 3 files changed, 49 insertions(+), 47 deletions(-) diff --git a/jetty-http3/http3-server/src/main/java/org/eclipse/jetty/http3/server/internal/HttpChannelOverHTTP3.java b/jetty-http3/http3-server/src/main/java/org/eclipse/jetty/http3/server/internal/HttpChannelOverHTTP3.java index f91b831fece..06554f7005b 100644 --- a/jetty-http3/http3-server/src/main/java/org/eclipse/jetty/http3/server/internal/HttpChannelOverHTTP3.java +++ b/jetty-http3/http3-server/src/main/java/org/eclipse/jetty/http3/server/internal/HttpChannelOverHTTP3.java @@ -297,16 +297,12 @@ public class HttpChannelOverHTTP3 extends HttpChannel } } - Stream.Data data = stream.readData(); - if (data != null) + HttpInput.Content result = readContent(); + + if (result != null) { - HttpInput.Content result = newContent(data); - try (AutoLock l = lock.lock()) - { - if (LOG.isDebugEnabled()) - LOG.debug("need content read content {} on {}", result, this); - content = result; - } + if (LOG.isDebugEnabled()) + LOG.debug("need content read content {} on {}", this.content, this); return true; } @@ -322,40 +318,15 @@ public class HttpChannelOverHTTP3 extends HttpChannel HttpInput.Content result; try (AutoLock l = lock.lock()) { - if (content != null) - { - result = content; - if (!result.isSpecial()) - content = null; - if (LOG.isDebugEnabled()) - LOG.debug("produced content {} on {}", result, this); - return result; - } + result = content; } - Stream.Data data = stream.readData(); - if (LOG.isDebugEnabled()) - LOG.debug("read {} on {}", data, this); - if (data == null) + if (result == null) + result = readContent(); + + if (result == null) return null; - result = newContent(data); - try (AutoLock l = lock.lock()) - { - content = result; - } - - boolean handle = onContent(result); - - boolean isLast = data.isLast(); - if (isLast) - { - boolean handleContent = onContentComplete(); - // This will generate EOF -> must happen before onContentProducible(). - boolean handleRequest = onRequestComplete(); - handle |= handleContent | handleRequest; - } - if (!result.isSpecial()) { HttpInput.Content newContent = result.isEof() ? new HttpInput.EofContent() : null; @@ -365,10 +336,41 @@ public class HttpChannelOverHTTP3 extends HttpChannel } } if (LOG.isDebugEnabled()) - LOG.debug("produced new content {} on {}", result, this); + LOG.debug("produced content {} on {}", result, this); return result; } + private HttpInput.Content readContent() + { + Stream.Data data = stream.readData(); + if (LOG.isDebugEnabled()) + LOG.debug("read data {} on {}", data, this); + if (data != null) + { + HttpInput.Content result = newContent(data); + + boolean handle = onContent(result); + + try (AutoLock l = lock.lock()) + { + if (LOG.isDebugEnabled()) + LOG.debug("read content {} on {}", result, this); + content = result; + } + + if (data.isLast()) + { + boolean handleContent = onContentComplete(); + // This will generate EOF -> must happen before onContentProducible(). + boolean handleRequest = onRequestComplete(); + handle |= handleContent | handleRequest; + } + + return result; + } + return null; + } + private HttpInput.Content newContent(Stream.Data data) { return new DataContent(data); diff --git a/jetty-quic/quic-quiche/src/main/java/org/eclipse/jetty/quic/quiche/QuicheConnection.java b/jetty-quic/quic-quiche/src/main/java/org/eclipse/jetty/quic/quiche/QuicheConnection.java index f7be7daf52f..25b3c09967d 100644 --- a/jetty-quic/quic-quiche/src/main/java/org/eclipse/jetty/quic/quiche/QuicheConnection.java +++ b/jetty-quic/quic-quiche/src/main/java/org/eclipse/jetty/quic/quiche/QuicheConnection.java @@ -596,7 +596,7 @@ public class QuicheConnection if (written == LibQuiche.quiche_error.QUICHE_ERR_DONE) return; if (written < 0L) - throw new IOException(" failed to write FIN to stream " + streamId + "; err=" + LibQuiche.quiche_error.errToString(written)); + throw new IOException("failed to write FIN to stream " + streamId + "; err=" + LibQuiche.quiche_error.errToString(written)); } } diff --git a/tests/test-http-client-transport/src/test/java/org/eclipse/jetty/http/client/HttpClientLoadTest.java b/tests/test-http-client-transport/src/test/java/org/eclipse/jetty/http/client/HttpClientLoadTest.java index b487a4450cf..1a81c557b26 100644 --- a/tests/test-http-client-transport/src/test/java/org/eclipse/jetty/http/client/HttpClientLoadTest.java +++ b/tests/test-http-client-transport/src/test/java/org/eclipse/jetty/http/client/HttpClientLoadTest.java @@ -92,14 +92,14 @@ public class HttpClientLoadTest extends AbstractTest IntStream.range(0, runs).forEach(j -> - run(iterations))); + run(transport, iterations))); } - private void run(int iterations) + private void run(Transport transport, int iterations) { CountDownLatch latch = new CountDownLatch(iterations); List failures = new ArrayList<>(); @@ -173,7 +173,7 @@ public class HttpClientLoadTest extends AbstractTest 0 ? iterations * 1000L / elapsed : -1); + logger.info("{} {} requests in {} ms, {} req/s", iterations, transport, elapsed, elapsed > 0 ? iterations * 1000L / elapsed : -1); for (String failure : failures) {