majek / puka

Puka - the opinionated RabbitMQ client
https://github.com/majek/puka
Other
182 stars 34 forks source link

set fcntl.FD_CLOEXEC on socket to prevent leaked handles #24

Closed kung-foo closed 12 years ago

kung-foo commented 12 years ago

We had several situations where an app creates a puka connection and then later on, spawns various new processes using subprocess.Popen(). If the app crashed or was restarted, the puka socket descriptor would still be held open by the now orphaned child processes. Since the connections are still open, rabbit would not release the unacknowledged messages. Setting fcntl.FD_CLOEXEC forces the handles to be closed immediately after the fork.

Several other python projects use similar code. Tornado's ioloop (before the multi-process support) used the same technique.

Python 3.2 will change the default behavior subprocess.Popen() to close all handles.

majek commented 12 years ago

I guess this patch doesn't hurt.