Skip to content

Commit

Permalink
Merge pull request #4446 from eclipse/jetty-9.4.x-4444-tls_idle_timeout
Browse files Browse the repository at this point in the history
Fixes #4444 -  Connection timeout intermittently when using jetty 9.4…
  • Loading branch information
sbordet committed Jan 17, 2020
2 parents 19e91a6 + fd52ff6 commit 692d901
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 10 deletions.
39 changes: 33 additions & 6 deletions jetty-io/src/main/java/org/eclipse/jetty/io/ssl/SslConnection.java
Expand Up @@ -862,6 +862,11 @@ protected void needsFillInterest()
{
interest = true;
_fillState = FillState.INTERESTED;
if (_flushState == FlushState.IDLE && BufferUtil.hasContent(_encryptedOutput))
{
_flushState = FlushState.WRITING;
write = _encryptedOutput;
}
}
break;

Expand Down Expand Up @@ -1279,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);
}
}
}

Expand Down Expand Up @@ -1489,19 +1511,23 @@ private final class IncompleteWriteCallback implements Callback, Invocable
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();
Expand All @@ -1520,7 +1546,8 @@ public void failed(final Throwable x)
releaseEncryptedOutputBuffer();

_flushState = FlushState.IDLE;
failFillInterest = _fillState == FillState.WAIT_FOR_FLUSH;
failFillInterest = _fillState == FillState.WAIT_FOR_FLUSH ||
_fillState == FillState.INTERESTED;
if (failFillInterest)
_fillState = FillState.IDLE;
}
Expand Down
Expand Up @@ -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);
Expand Down Expand Up @@ -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));
}
}
}
Expand Down

0 comments on commit 692d901

Please sign in to comment.