pushyrpc / pushy

Easy-as RPC. Zero-server RPC for Python and Java.
http://github.com/pushyrpc/pushy
45 stars 18 forks source link

subprocess on UNIX may lead to process hang #11

Closed axw closed 12 years ago

axw commented 12 years ago

When calling subprocess.Popen via Pushy on UNIX, the server process may hang. I believe this occurs when the process forks, and the child and parent processes acquire different values for the message reading locks/conditions, etc., in BaseConnection.


Imported from Launchpad using lp2gh.

axw commented 12 years ago

(by axwalk) The problem was largely due to the use of the original sys.stdin when creating the pushy.protocol.Connection in client.py. Since the subprocess will replace file descriptor 0 (stdin), any attempts to access a proxy object will lead to reading from the new pipe, rather than the original stdin.

A few changes were made. First and foremost, I have dup'd sys.stdin in client.py and passed that to pushy.protocol.Connection instead. Second, although unnecessary to fix this bug, I've removed calls to self.send_response out of Connection, and have request handlers simply return the result. BaseConnection.__handle will now call self.send_response.

There is one more thing that needs to be done before this can be closed. If the child process that results from the fork in subprocess.Popen attempts to access a proxy object, it may receive asynchronous requests while waiting for a response. We need these messages need to be handled in the parent process, and so we need a way of asking the peer to resend a message.

axw commented 12 years ago

(by axwalk) I have decided to omit the "message resending" referred to above, as this problem has remained a theoretical one thus far. I have not been able to produce this defect. If it becomes problematic, a new bug may be raised later for it to be dealt with. Otherwise it's just holding up the 0.3 release, and complicating the code.