Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #4444 - Connection timeout intermittently when using jetty 9.4… #4446

Merged
merged 3 commits into from Jan 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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