Skip to content

Commit

Permalink
Issue #4217 - SslConnection DecryptedEndpoint flush eternal busy loop
Browse files Browse the repository at this point in the history
+ Cleanup from review

Signed-off-by: Joakim Erdfelt <[email protected]>
  • Loading branch information
joakime committed Oct 30, 2019
1 parent 93a5ff0 commit e137ee3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;

import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLServerSocket;
import javax.net.ssl.SSLSocket;
Expand All @@ -41,10 +40,12 @@
import org.eclipse.jetty.client.util.FutureResponseListener;
import org.eclipse.jetty.http.HttpScheme;
import org.eclipse.jetty.http.HttpStatus;
import org.eclipse.jetty.toolchain.test.JDK;
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
import org.eclipse.jetty.util.ssl.SslContextFactory;
import org.junit.After;
import org.junit.Assert;
import org.junit.Assume;
import org.junit.Before;
import org.junit.Test;

Expand All @@ -59,6 +60,8 @@ public class SslBytesClientTest extends SslBytesTest
@Before
public void init() throws Exception
{
// Disable for JDK 9 and above.
Assume.assumeFalse(JDK.IS_9);
threadPool = Executors.newCachedThreadPool();

client = new HttpClient(new SslContextFactory(true));
Expand Down
28 changes: 9 additions & 19 deletions jetty-io/src/main/java/org/eclipse/jetty/io/ssl/SslConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,7 @@ public int fill(ByteBuffer buffer) throws IOException
// We also need an app buffer, but can use the passed buffer if it is big enough
ByteBuffer app_in;
int appBufferSize = getApplicationBufferSize();

if (BufferUtil.space(buffer) > appBufferSize)
app_in = buffer;
else if (_decryptedInput == null)
Expand Down Expand Up @@ -692,6 +693,14 @@ else if (_decryptedInput == null)
_underFlown = unwrapResultStatus == Status.BUFFER_UNDERFLOW ||
unwrapResultStatus == Status.OK && unwrapResult.bytesConsumed() == 0 && unwrapResult.bytesProduced() == 0;

if (_underFlown)
{
if (net_filled < 0 && _sslEngine.getUseClientMode())
closeInbound();
if (net_filled <= 0)
return net_filled;
}

switch (unwrapResultStatus)
{
case CLOSED:
Expand Down Expand Up @@ -732,25 +741,6 @@ else if (_decryptedInput == null)
throw new IllegalStateException("Unexpected unwrap result " + unwrapResultStatus);

case BUFFER_UNDERFLOW:
if (net_filled > 0)
break decryption; // try filling some more
_underFlown = true;
if (net_filled < 0 && _sslEngine.getUseClientMode())
{
try
{
closeInbound();
}
catch (SSLException closeFailure)
{
Throwable handshakeFailure = new SSLHandshakeException("Abruptly closed by peer");
handshakeFailure.initCause(closeFailure);
throw handshakeFailure;
}

return -1;
}
return net_filled;
case OK:
{
if (unwrapHandshakeStatus == HandshakeStatus.FINISHED)
Expand Down

0 comments on commit e137ee3

Please sign in to comment.