Message10762

Author nickmbailey
Recipients nickmbailey
Date 2016-02-22.23:04:31
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1456182273.0.0.638747602719.issue2471@psf.upfronthosting.co.za>
In-reply-to
Content
I think Jython is using netty's channel future incorrectly and causing a deadlock.

The netty docs say it is preferred to add asynchronous listeners rather than calling sync()/await() directly.

https://github.com/netty/netty/blob/4.0/transport/src/main/java/io/netty/channel/ChannelFuture.java#L96

Jython is doing things the incorrect way when closing sockets:

https://github.com/jythontools/jython/blob/master/Lib/_socket.py#L1059

In my twisted application running on jython I can easily cause deadlocks by using apache bench to load test the twisted web server. I think we can safely just add the rest of the shutdown code as a listener on the channel future like so:

diff --git a/Lib/_socket.py b/Lib/_socket.py
index 3b658e5..56d8f4d 100644
--- a/Lib/_socket.py
+++ b/Lib/_socket.py
@@ -1055,11 +1055,10 @@ class _realsocket(object):
             if self.channel is None:
                 return

-            try:
-                self.channel.close().sync()
-            except RejectedExecutionException:
-                # Do not care about tasks that attempt to schedule after close
-                pass
+            closeFuture = self.channel.close()
+            closeFuture.addListener(self.finishClosing)
+
+    def finishClosing(self, _):
         if self.socket_type == SERVER_SOCKET:
             log.debug("Shutting down server socket parent group", extra={"sock": self})
             self.parent_group.shutdownGracefully(0, 100, TimeUnit.MILLISECONDS)


If I apply that patch, I can no longer cause the deadlock.
History
Date User Action Args
2016-02-22 23:04:33nickmbaileysetrecipients: + nickmbailey
2016-02-22 23:04:33nickmbaileysetmessageid: <1456182273.0.0.638747602719.issue2471@psf.upfronthosting.co.za>
2016-02-22 23:04:32nickmbaileylinkissue2471 messages
2016-02-22 23:04:31nickmbaileycreate