From a67e5502078f7dc03b0faa53d2965d5c257e0399 Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Tue, 25 Oct 2011 19:58:21 +0200 Subject: [PATCH] Merge changes back from 3.2 branch which fixes a deadlock in the SslHandler. See NETTY-443 --- .../jboss/netty/handler/ssl/SslHandler.java | 68 +++++++++++-------- 1 file changed, 38 insertions(+), 30 deletions(-) diff --git a/src/main/java/org/jboss/netty/handler/ssl/SslHandler.java b/src/main/java/org/jboss/netty/handler/ssl/SslHandler.java index 51915b463f..bf6926a710 100644 --- a/src/main/java/org/jboss/netty/handler/ssl/SslHandler.java +++ b/src/main/java/org/jboss/netty/handler/ssl/SslHandler.java @@ -871,42 +871,50 @@ public class SslHandler extends FrameDecoder loop: for (;;) { SSLEngineResult result; + boolean needsHandshake = false; synchronized (handshakeLock) { if (!handshaken && !handshaking && !engine.getUseClientMode() && !engine.isInboundDone() && !engine.isOutboundDone()) { - handshake(); - } - - result = engine.unwrap(inNetBuf, outAppBuf); - - final HandshakeStatus handshakeStatus = result.getHandshakeStatus(); - handleRenegotiation(handshakeStatus); - switch (handshakeStatus) { - case NEED_UNWRAP: - if (inNetBuf.hasRemaining() && !engine.isInboundDone()) { - break; - } else { - break loop; - } - case NEED_WRAP: - wrapNonAppData(ctx, channel); - break; - case NEED_TASK: - runDelegatedTasks(); - break; - case FINISHED: - setHandshakeSuccess(channel); - needsWrap = true; - break loop; - case NOT_HANDSHAKING: - needsWrap = true; - break loop; - default: - throw new IllegalStateException( - "Unknown handshake status: " + handshakeStatus); + needsHandshake = true; + } } + if (needsHandshake) { + handshake(); + } + + synchronized (handshakeLock) { + result = engine.unwrap(inNetBuf, outAppBuf); + } + + final HandshakeStatus handshakeStatus = result.getHandshakeStatus(); + handleRenegotiation(handshakeStatus); + switch (handshakeStatus) { + case NEED_UNWRAP: + if (inNetBuf.hasRemaining() && !engine.isInboundDone()) { + break; + } else { + break loop; + } + case NEED_WRAP: + wrapNonAppData(ctx, channel); + break; + case NEED_TASK: + runDelegatedTasks(); + break; + case FINISHED: + setHandshakeSuccess(channel); + needsWrap = true; + break loop; + case NOT_HANDSHAKING: + needsWrap = true; + break loop; + default: + throw new IllegalStateException( + "Unknown handshake status: " + handshakeStatus); + } + } if (needsWrap) {