From 2acd74db83df1bf54832b749ed92b13866caa7a3 Mon Sep 17 00:00:00 2001 From: Trustin Lee Date: Mon, 1 Aug 2011 01:32:55 +0900 Subject: [PATCH] NETTY-410 NioWorker write deadlock Applied the patch provided by Greg Dhuse. --- .../netty/channel/socket/nio/NioWorker.java | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/jboss/netty/channel/socket/nio/NioWorker.java b/src/main/java/org/jboss/netty/channel/socket/nio/NioWorker.java index 7f9ebed441..0bf1dc51c9 100644 --- a/src/main/java/org/jboss/netty/channel/socket/nio/NioWorker.java +++ b/src/main/java/org/jboss/netty/channel/socket/nio/NioWorker.java @@ -506,17 +506,23 @@ class NioWorker implements Runnable { } } channel.inWriteNowLoop = false; + + // Initially, the following block was executed after releasing + // the writeLock, but there was a race condition, and it has to be + // executed before releasing the writeLock: + // + // https://issues.jboss.org/browse/NETTY-410 + // + if (open) { + if (addOpWrite) { + setOpWrite(channel); + } else if (removeOpWrite) { + clearOpWrite(channel); + } + } } fireWriteComplete(channel, writtenBytes); - - if (open) { - if (addOpWrite) { - setOpWrite(channel); - } else if (removeOpWrite) { - clearOpWrite(channel); - } - } } private void setOpWrite(NioSocketChannel channel) {