Better fix for the SslHandler dead lock

This commit is contained in:
Trustin Lee 2009-05-13 01:08:40 +00:00
parent 4eee24dc2c
commit 7e3ecf6b46

View File

@ -688,7 +688,6 @@ public class SslHandler extends FrameDecoder implements ChannelDownstreamHandler
loop: loop:
for (;;) { for (;;) {
SSLEngineResult result; SSLEngineResult result;
boolean needsNonAppWrap = false;
synchronized (handshakeLock) { synchronized (handshakeLock) {
if (initialHandshake && !engine.getUseClientMode() && if (initialHandshake && !engine.getUseClientMode() &&
!engine.isInboundDone() && !engine.isOutboundDone()) { !engine.isInboundDone() && !engine.isOutboundDone()) {
@ -710,9 +709,7 @@ public class SslHandler extends FrameDecoder implements ChannelDownstreamHandler
break loop; break loop;
} }
case NEED_WRAP: case NEED_WRAP:
// wrapNonAppData must be called wrapNonAppData(ctx, channel);
// while handshakeLock is not hold.
needsNonAppWrap = true;
break; break;
case NEED_TASK: case NEED_TASK:
runDelegatedTasks(); runDelegatedTasks();
@ -730,14 +727,15 @@ public class SslHandler extends FrameDecoder implements ChannelDownstreamHandler
result.getHandshakeStatus()); result.getHandshakeStatus());
} }
} }
if (needsNonAppWrap) {
wrapNonAppData(ctx, channel);
}
} }
if (needsWrap) { if (needsWrap) {
wrap(ctx, channel); // wrap() acquires pendingUnencryptedWrites first and then
// handshakeLock. If handshakeLock is already hold by the
// current thread, calling wrap() will lead to a dead lock.
if (!Thread.holdsLock(handshakeLock)) {
wrap(ctx, channel);
}
} }
outAppBuf.flip(); outAppBuf.flip();