Fixed issue: NETTY-64 (Dead lock during SSL handshake)

* Acquired handshakeLock explicitly when sending handshake messages and executing delegated tasks
This commit is contained in:
Trustin Lee 2008-11-14 12:05:49 +00:00
parent 7123581038
commit 3b5c36782d

View File

@ -118,7 +118,7 @@ public class SslHandler extends FrameDecoder {
private final Executor delegatedTaskExecutor; private final Executor delegatedTaskExecutor;
private final boolean startTls; private final boolean startTls;
private final Object handshakeLock = new Object(); final Object handshakeLock = new Object();
private volatile boolean handshaking; private volatile boolean handshaking;
private volatile boolean handshaken; private volatile boolean handshaken;
private volatile ChannelFuture handshakeFuture; private volatile ChannelFuture handshakeFuture;
@ -550,7 +550,13 @@ public class SslHandler extends FrameDecoder {
SSLEngineResult result; SSLEngineResult result;
try { try {
for (;;) { for (;;) {
result = engine.wrap(EMPTY_BUFFER, outNetBuf); if (handshaking) {
synchronized (handshakeLock) {
result = engine.wrap(EMPTY_BUFFER, outNetBuf);
}
} else {
result = engine.wrap(EMPTY_BUFFER, outNetBuf);
}
if (result.bytesProduced() > 0) { if (result.bytesProduced() > 0) {
outNetBuf.flip(); outNetBuf.flip();
@ -648,7 +654,14 @@ public class SslHandler extends FrameDecoder {
private void runDelegatedTasks() { private void runDelegatedTasks() {
Runnable task; Runnable task;
while ((task = engine.getDelegatedTask()) != null) { while ((task = engine.getDelegatedTask()) != null) {
delegatedTaskExecutor.execute(task); final Runnable t = task;
delegatedTaskExecutor.execute(new Runnable() {
public void run() {
synchronized (handshakeLock) {
t.run();
}
}
});
} }
} }