ocaml-multicore / eio

Effects-based direct-style IO for multicore OCaml
Other
548 stars 66 forks source link

Eio_posix: don't reap non-Eio child processes #562

Closed talex5 closed 1 year ago

talex5 commented 1 year ago

Previously, eio_posix installed a signal handler that would reap all child processs. However, this may cause problems if some other library is used to spawn a process (e.g. Stdlib.Unix or Lwt).

Now, it polls every known child process individually when signalled, so only processes spawned by Eio will be reaped. This is what Lwt does too (https://github.com/ocsigen/lwt/blob/cc05e2bda6c34126a3fd8d150ee7cddb3b8a440b/src/unix/lwt_unix.cppo.ml#L2364).

This is slightly slower than the old code:

EIO_BACKEND=posix dune exec -- ./stress/stress_proc.exe
+Finished process stress test: ran 10000 processes in 2.70s   # Old code
+Finished process stress test: ran 10000 processes in 2.89s   # New code

Eio_linux is unaffected, as it uses process descriptors instead of signals.

This is needed for https://github.com/ocsigen/lwt/issues/991.