From d5e962e7d02fe6f724d18b1bf00420a1530d087f Mon Sep 17 00:00:00 2001 From: Simone Bordet Date: Mon, 30 Dec 2019 17:18:49 +0100 Subject: [PATCH] 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 465a3ac8eb93..26b969f545b7 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 void doShutdownOutput() { // 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 994b2a39f413..6c37691bdb28 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 void testBlockedClose() throws Exception 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 void testBlockedClose() throws Exception assertTrue(__onIncompleteFlush.get()); ((TestEP)_lastEndp).getWriteFlusher().completeWrite(); len = client.getInputStream().read(buffer); - assertThat(len, is(len)); + assertThat(len, is(-1)); } } }