Ticket #856 (defect)
Opened 2 months ago
Last modified 2 weeks ago
Prevent open sockets from being inherited by child processes
Status: closed (fixed)
| Reported by: | guest | Assigned to: | fumanchu |
|---|---|---|---|
| Priority: | normal | Milestone: | 3.1 |
| Component: | wsgiserver | Keywords: | |
| Cc: | nicolas.grilly@garden-paris.com |
Some applications require to launch a subprocess directly from a CherryPy handler (for example to call a Unix command or to achieve a long running task). The subprocess inherits all open sockets from its parent process. Then, if the subprocess is long living, it will keep the sockets open. This is especially embarrassing when using HTTP keep-alive, because the browser can be blocked by communicating to a socket closed by CherryPy but still open in the subprocess...
Attached to this ticket is a patch against the current CherryPy trunk:
- On POSIX systems, we set the close-on-exec flag.
- On Win32 systems, we set the sockets as non inheritable.
This method is used in some modules of the Python standard library (SimpleXMLRPCServer, subprocess and tempfile).
TODO: Note that if another thread spawns a process in between the socket creation and the call to prevent_socket_inheritance, we're still out of luck. A solution for Windows is proposed in http://bugs.python.org/issue3006, by directly coding it in C, when holding the Global Interpreter Lock.
Attachments
Change History
09/10/08 19:48:50: Modified by guest
- attachment ticket856.patch added.
09/10/08 19:50:29: Modified by nicolas.grilly@garden-paris.com
- cc set to nicolas.grilly@garden-paris.com.
09/27/08 13:32:21: Modified by fumanchu
- status changed from new to assigned.
- description changed.
- milestone set to 3.1.
Reformatted.
09/27/08 13:52:21: Modified by fumanchu
Applied in [2038]. Thanks for the excellent work!
09/27/08 18:30:08: Modified by Nicolas Grilly
Thanks for committing my patch!
And thanks for refactoring my code (you cleverly removed duplication of the "dummy" function).
11/08/08 15:19:22: Modified by fumanchu
- status changed from assigned to closed.
- resolution set to fixed.


Updated my email to follow the ticket