From 4bf26c31e97790d89d312edfdd9022bf07c952be Mon Sep 17 00:00:00 2001 From: Trustin Lee Date: Mon, 1 Aug 2011 04:00:01 +0900 Subject: [PATCH] NETTY-410 NioWorker write deadlock Applied the patch provided by Greg Dhuse. --- .../channel/socket/nio/NioDatagramWorker.java | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/jboss/netty/channel/socket/nio/NioDatagramWorker.java b/src/main/java/org/jboss/netty/channel/socket/nio/NioDatagramWorker.java index 688ffe5d22..86b6a0e405 100644 --- a/src/main/java/org/jboss/netty/channel/socket/nio/NioDatagramWorker.java +++ b/src/main/java/org/jboss/netty/channel/socket/nio/NioDatagramWorker.java @@ -568,15 +568,21 @@ class NioDatagramWorker 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 (addOpWrite) { + setOpWrite(channel); + } else if (removeOpWrite) { + clearOpWrite(channel); + } } fireWriteComplete(channel, writtenBytes); - - if (addOpWrite) { - setOpWrite(channel); - } else if (removeOpWrite) { - clearOpWrite(channel); - } } private void setOpWrite(final NioDatagramChannel channel) {