From 725a54d07a8dbb47d3f18a180a6c3eed45b9cbf5 Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Sat, 29 Dec 2012 08:37:39 +0100 Subject: [PATCH] [#865] Fix regression in SslHandler which can cause to miss a wrap() call --- .../jboss/netty/handler/ssl/SslHandler.java | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 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 4d9ce80a71..ca35b40ce8 100644 --- a/src/main/java/org/jboss/netty/handler/ssl/SslHandler.java +++ b/src/main/java/org/jboss/netty/handler/ssl/SslHandler.java @@ -1244,20 +1244,19 @@ public class SslHandler extends FrameDecoder "Unknown handshake status: " + handshakeStatus); } } - - if (needsWrap) { - // wrap() acquires pendingUnencryptedWrites first and then - // handshakeLock. If handshakeLock is already hold by the - // current thread, calling wrap() will lead to a dead lock - // i.e. pendingUnencryptedWrites -> handshakeLock vs. - // handshakeLock -> pendingUnencryptedLock -> handshakeLock - // - // There is also a same issue between pendingEncryptedWrites - // and pendingUnencryptedWrites. - if (!Thread.holdsLock(handshakeLock) && + } + if (needsWrap) { + // wrap() acquires pendingUnencryptedWrites first and then + // handshakeLock. If handshakeLock is already hold by the + // current thread, calling wrap() will lead to a dead lock + // i.e. pendingUnencryptedWrites -> handshakeLock vs. + // handshakeLock -> pendingUnencryptedLock -> handshakeLock + // + // There is also a same issue between pendingEncryptedWrites + // and pendingUnencryptedWrites. + if (!Thread.holdsLock(handshakeLock) && !pendingEncryptedWritesLock.isHeldByCurrentThread()) { - wrap(ctx, channel); - } + wrap(ctx, channel); } } outAppBuf.flip();