From 5794584aeab5feb0e05df71ca465ffe3d8148e4b Mon Sep 17 00:00:00 2001 From: Simone Bordet Date: Thu, 26 Dec 2019 18:57:00 +0100 Subject: [PATCH 1/3] Fixes #4444 - Connection timeout intermittently when using jetty 9.4.25. Fixed handling of encrypted bytes to write in needsFillInterest() when the TLS handshake status is NOT_HANDSHAKING. Signed-off-by: Simone Bordet --- .../org/eclipse/jetty/io/ssl/SslConnection.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/jetty-io/src/main/java/org/eclipse/jetty/io/ssl/SslConnection.java b/jetty-io/src/main/java/org/eclipse/jetty/io/ssl/SslConnection.java index bb202a8f72b..465a3ac8eb9 100644 --- a/jetty-io/src/main/java/org/eclipse/jetty/io/ssl/SslConnection.java +++ b/jetty-io/src/main/java/org/eclipse/jetty/io/ssl/SslConnection.java @@ -862,6 +862,11 @@ public class SslConnection extends AbstractConnection implements Connection.Upgr { interest = true; _fillState = FillState.INTERESTED; + if (_flushState == FlushState.IDLE && BufferUtil.hasContent(_encryptedOutput)) + { + _flushState = FlushState.WRITING; + write = _encryptedOutput; + } } break; @@ -1489,19 +1494,23 @@ public class SslConnection extends AbstractConnection implements Connection.Upgr public void succeeded() { boolean fillable; + boolean interested; synchronized (_decryptedEndPoint) { if (LOG.isDebugEnabled()) LOG.debug("IncompleteWriteCB succeeded {}", SslConnection.this); - releaseEncryptedOutputBuffer(); _flushState = FlushState.IDLE; + + interested = _fillState == FillState.INTERESTED; fillable = _fillState == FillState.WAIT_FOR_FLUSH; if (fillable) _fillState = FillState.IDLE; } - if (fillable) + if (interested) + ensureFillInterested(); + else if (fillable) _decryptedEndPoint.getFillInterest().fillable(); _decryptedEndPoint.getWriteFlusher().completeWrite(); @@ -1520,7 +1529,8 @@ public class SslConnection extends AbstractConnection implements Connection.Upgr releaseEncryptedOutputBuffer(); _flushState = FlushState.IDLE; - failFillInterest = _fillState == FillState.WAIT_FOR_FLUSH; + failFillInterest = _fillState == FillState.WAIT_FOR_FLUSH || + _fillState == FillState.INTERESTED; if (failFillInterest) _fillState = FillState.IDLE; } From d5e962e7d02fe6f724d18b1bf00420a1530d087f Mon Sep 17 00:00:00 2001 From: Simone Bordet Date: Mon, 30 Dec 2019 17:18:49 +0100 Subject: [PATCH 2/3] Fixes #4444 - Connection timeout intermittently when using jetty 9.4.25. Fixed write in doShutdownOutput() by updating the state before the write, so that needsFillInterest() can check whether to also do a write or not. Signed-off-by: Simone Bordet --- .../eclipse/jetty/io/ssl/SslConnection.java | 23 ++++++++++++++++--- .../eclipse/jetty/io/SslConnectionTest.java | 5 +--- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/jetty-io/src/main/java/org/eclipse/jetty/io/ssl/SslConnection.java b/jetty-io/src/main/java/org/eclipse/jetty/io/ssl/SslConnection.java index 465a3ac8eb9..26b969f545b 100644 --- a/jetty-io/src/main/java/org/eclipse/jetty/io/ssl/SslConnection.java +++ b/jetty-io/src/main/java/org/eclipse/jetty/io/ssl/SslConnection.java @@ -1284,9 +1284,26 @@ public class SslConnection extends AbstractConnection implements Connection.Upgr { // If we still can't flush, but we are not closing the endpoint, // let's just flush the encrypted output in the background. - ByteBuffer write = _encryptedOutput; - if (BufferUtil.hasContent(write)) - endPoint.write(Callback.from(Callback.NOOP::succeeded, t -> endPoint.close()), write); + ByteBuffer write = null; + synchronized (_decryptedEndPoint) + { + if (BufferUtil.hasContent(_encryptedOutput)) + { + write = _encryptedOutput; + _flushState = FlushState.WRITING; + } + } + if (write != null) + { + endPoint.write(Callback.from(() -> + { + synchronized (_decryptedEndPoint) + { + _flushState = FlushState.IDLE; + releaseEncryptedOutputBuffer(); + } + }, t -> endPoint.close()), write); + } } } diff --git a/jetty-io/src/test/java/org/eclipse/jetty/io/SslConnectionTest.java b/jetty-io/src/test/java/org/eclipse/jetty/io/SslConnectionTest.java index 994b2a39f41..6c37691bdb2 100644 --- a/jetty-io/src/test/java/org/eclipse/jetty/io/SslConnectionTest.java +++ b/jetty-io/src/test/java/org/eclipse/jetty/io/SslConnectionTest.java @@ -485,9 +485,6 @@ public class SslConnectionTest server.configureBlocking(false); _manager.accept(server); - //__startBlocking.set(5); - //__blockFor.set(3); - client.getOutputStream().write("Short".getBytes(StandardCharsets.UTF_8)); byte[] buffer = new byte[1024]; int len = client.getInputStream().read(buffer); @@ -515,7 +512,7 @@ public class SslConnectionTest assertTrue(__onIncompleteFlush.get()); ((TestEP)_lastEndp).getWriteFlusher().completeWrite(); len = client.getInputStream().read(buffer); - assertThat(len, is(len)); + assertThat(len, is(-1)); } } } From 20af3c1b130b9394afb5e76e8ce056c942edce8e Mon Sep 17 00:00:00 2001 From: Chris Walker Date: Fri, 17 Jan 2020 12:25:04 -0600 Subject: [PATCH 3/3] Noted 9.3 is deprecated --- .../main/asciidoc/quick-start/introduction/what-version.adoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jetty-documentation/src/main/asciidoc/quick-start/introduction/what-version.adoc b/jetty-documentation/src/main/asciidoc/quick-start/introduction/what-version.adoc index 3332e94d198..899d25c5d1a 100644 --- a/jetty-documentation/src/main/asciidoc/quick-start/introduction/what-version.adoc +++ b/jetty-documentation/src/main/asciidoc/quick-start/introduction/what-version.adoc @@ -35,7 +35,7 @@ _____ |Version |Year |Home |Min JVM |Protocols |Servlet |JSP |Status |10 |2019- |Eclipse |11 ^(1)^ |HTTP/1.1 (RFC 7230), HTTP/2 (RFC 7540), WebSocket (RFC 6455, JSR 356), FastCGI |4.0.2 |2.3 |*UNSTABLE / Alpha* |9.4 |2016- |Eclipse |1.8 |HTTP/1.1 (RFC 7230), HTTP/2 (RFC 7540), WebSocket (RFC 6455, JSR 356), FastCGI |3.1 |2.3 |Stable -|9.3 |2015- |Eclipse |1.8 ^(2)^ |HTTP/1.1 (RFC 7230), HTTP/2 (RFC 7540), WebSocket (RFC 6455, JSR 356), FastCGI |3.1 |2.3 |Stable +|9.3 |2015- |Eclipse |1.8 ^(2)^ |HTTP/1.1 (RFC 7230), HTTP/2 (RFC 7540), WebSocket (RFC 6455, JSR 356), FastCGI |3.1 |2.3 |Deprecated |9.2 |2014-2018 |Eclipse |1.7 ^(2)^ |HTTP/1.1 RFC2616, javax.websocket, SPDY v3 |3.1 |2.3 |Deprecated / *End of Life January 2018* |9.1 |2013-2014 |Eclipse |1.7 ^(2)^ |HTTP/1.1 RFC2616 |3.1 |2.3 |Deprecated / *End of Life May 2014* |9.0 |2013-2013 |Eclipse |1.7 ^(2)^ |HTTP/1.1 RFC2616 |3.1-beta |2.3 |Deprecated / *End of Life November 2013*