-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Writing custom events causes GC deadlocks #12897
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I wondered how other locking code avoids this issue. The way that runtime/io.c manages its per-channel locks is: first |
I think that we should document somewhere in the runtime code that locks cannot be safely used across OCaml callbacks due to this type of issue. I looked at the other usage of |
One way to avoid the issue, while remaining on the C side, would be to use |
On OCaml 5.1.1, this program hangs very quickly for me:
The output is typically:
This is a simplified version of what happens when tracing Eio's HTTP benchmark. The
Gc.minor
call inencode
doesn't seem to be necessary (caml_runtime_events_user_write
callsalloc_and_clear_stack_parent
, which allocates), but triggering the bug without it takes longer.I think what is happening is:
write_buffer_lock
, then decides to do a GC while holding it. It waits for domain 1 to be ready.write_buffer_lock
(I'm not sure why the C code is managing the (single) write buffer. It would probably be safer to let the OCaml code deal with that and just call the events code with the buffer already filled in.)
/cc @sadiqj @OlivierNicole
The text was updated successfully, but these errors were encountered: