stripe / subprocess

A port of Python's subprocess module to Ruby
MIT License
208 stars 17 forks source link

Run a separate thread to wakeup SIGCHLD listeners. #34

Closed nelhage-stripe closed 7 years ago

nelhage-stripe commented 7 years ago

This enables us to properly grab the @sigchld_mutex and synchronize with writers.

It turns out that signal handlers execute on the main thread and may interleave with other writers. This manifested as handle_sigchld writeing to pipes that had already been closed (by the IO.pipe) block, resulting in nasty exceptions.

By grabbing the lock, we ensure that we serialize reading the list of wakeup pipes properly with respect to writers. The signal handler now exists only to signal that thread, and is defensively coded against running at random moments in time.

r? @andrew-stripe cc @stripe/product-infra

nelhage-stripe commented 7 years ago

per IRL this isn't going to work