Conversation
|
Note: I wonder if there is a deeper problem here.
Maybe we can recommend to always use (Note: even with 4.x, there were reasons to recommend this, for example for Eventlog users, as |
|
It's not obvious to me why the child process uses the OCaml runtime. If we were to implement spawning using |
|
The In the medium term, maybe we could reconsider the idea of maintaining yet another implementation of |
Well, I find this questionable, even in OCaml 4. For example, there's a risk of double-flushing of OCaml channels (once in the parent, once in the child). resulting in duplicate output. |
|
Good point. I did wonder about flushing before the On the other hand, I think we do have OCaml programs that |
xavierleroy
left a comment
There was a problem hiding this comment.
OK, let's merge this as a bug fix and think about alternate implementations later. Can you please fix the Changes entry then squash-and-merge?
I really hope this pattern ( |
|
Thanks! I updated and rebased.
It fails on my machine on the first time that we try to release the runtime lock / enter a blocking section. (I'm slightly nervous at the idea that our options to fix the issue in a backward-compatible ways will be very limited once 5.0 and 4.14 are release without a coherent support for forking, but oh well, let's assume that nobody does that indeed.) |
For OCaml >= 5 it's required that you call caml_atfork_hook after C code calls fork. See: ocaml/ocaml#11111
The error-reporting code in ocamltest's
run_unix.cis incorrect with respect to the new Multicore runtime, because it tries to use the OCaml runtime (to write to an OCaml channel) without callingcaml_atfork_hookfirst.reproduction information
Add
at the entry of run_command_child in ocamltest/run_unix.c, then run
Observed output contains:
On my system, the core dump has the following backtrace:
The problem comes from trying to use the OCaml runtime from a forked
child, without calling the new Multicore-OCaml function
caml_atfork_hookfrom domain.h. At this point the forked child hasits domain lock in an incoherent state, and calling
caml_write_fdfails. (Compare the ceremony around fork() in ocamltest/run_unix.c and
in otherlibs/unix/unix_fork.c)
Note: the backtrace also shows that C files in ocamltest were not
compiled with debug information. The PR also adds CFLAGS=-g in
ocamlest/Makefile to fix this.