Commit ddf1aaa
Replace process_stubs.c with pure OCaml implementation for OCaml 5 multi-domain safety (#12757)
* Initial plan
* Use run_in_new_pool for filter phases to avoid idle domains during eval execution
The persistent pool (via run_with_pool) kept domain workers alive during eval
interpretation and callbacks, causing subprocess/IPC failures in eval tests.
Revert to run_in_new_pool which tears down the pool after each parallel section,
matching the pattern that works on development. The sctx.pool and run_with_pool
remain available for generators (e.g. genjvm) that use them during code generation.
Also restore the EnableParallelAnalyzer guard since the analyzer was specifically
identified as leaking when run in parallel (#12414).
Co-authored-by: Simn <634365+Simn@users.noreply.github.com>
* Revert filters.ml to base branch state
Co-authored-by: Simn <634365+Simn@users.noreply.github.com>
* Make process_stubs.c safe for OCaml 5 multi-domain programs
Two changes to fix eval subprocess failures when domainslib pool
domains are alive:
1. Add caml_enter_blocking_section/caml_leave_blocking_section to all
blocking process operations (read, write, waitpid, WaitForSingleObject,
ReadFile, WriteFile). Without these, the calling domain holds its
runtime lock during blocking I/O, preventing stop-the-world GC from
proceeding when worker domains need it. This causes GC stalls that
lead to pipe I/O corruption and timing issues.
2. Replace fork()+exec() with posix_spawn() on Unix. OCaml 5's
Unix.fork explicitly refuses to fork when domains are spawned
(caml_domain_is_multicore check). process_stubs.c bypassed this
safety check by calling fork() directly. In multi-threaded programs,
fork() can deadlock when worker threads hold internal locks (malloc
arenas, glibc internals). posix_spawn() avoids this by using
clone(CLONE_VM|CLONE_VFORK) internally on Linux.
Co-authored-by: Simn <634365+Simn@users.noreply.github.com>
* Replace process_stubs.c with pure OCaml implementation
Remove the C stubs entirely and implement Process using
Unix.create_process, which is domain-safe under OCaml 5.
This also refactors PipeThings.run_command to use Process.run
instead of duplicating the pipe+spawn logic.
The old C stubs had two issues in OCaml 5:
1. Missing caml_enter_blocking_section around blocking I/O
2. Direct fork() which is unsafe with multiple domains
Unix.create_process handles both correctly (it uses posix_spawn
internally on modern systems and properly releases the runtime lock).
Co-authored-by: Simn <634365+Simn@users.noreply.github.com>
* Fix error handling: convert Unix.Unix_error to Failure for eval compatibility
The old C stubs used caml_failwith for all errors, which eval catches
as Dynamic. Unix.create_process raises Unix.Unix_error instead, which
eval couldn't catch. Convert all Unix errors to Failure to preserve
backward compatibility.
Co-authored-by: Simn <634365+Simn@users.noreply.github.com>
* catch Unix_error in callers instead
* don't turn exit status into exceptions
* make Eof extend Exception
* catch constructor exception too
* back to running everything
* hmm
* Handle non-existent commands in Process.run without throwing
When Unix.create_process fails (e.g. command not found), return a
process with pre-closed pipes (reads return EOF) and exit code 127,
matching the old fork+exec behavior where fork always succeeded and
exec failure manifested as a non-zero exit code.
Add misc test to verify non-existent commands don't throw exceptions.
Co-authored-by: Simn <634365+Simn@users.noreply.github.com>
* Assert output in process-nonexistent misc test, guard kill against pid=0
The test now prints stdout_empty, stderr_empty, and exit_code values
and asserts them via compile.hxml.stdout (expected: empty pipes, code 127).
Also add pid > 0 guard in Process.kill as defense-in-depth against
sending signals to process group 0 for failed process objects.
Co-authored-by: Simn <634365+Simn@users.noreply.github.com>
* Preserve Unix.Unix_error info in all Process operations
- run: writes error message to stderr pipe so callers can read it
- read_stdout/read_stderr/write_stdin/close_stdin: include the
Unix error details (function, arg, message) in Failure exceptions
- Add unix_error_msg helper shared by all operations
- Test checks stderr is non-empty (not a specific message string)
for cross-platform compatibility
Co-authored-by: Simn <634365+Simn@users.noreply.github.com>
* reformat
* avoid some code duplication
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Simn <634365+Simn@users.noreply.github.com>
Co-authored-by: Simon Krajewski <simon@haxe.org>1 parent 3caa538 commit ddf1aaa
File tree
10 files changed
+205
-672
lines changed- .github/workflows
- libs/extc
- src
- compiler
- macro/eval
- std/haxe/io
- tests/misc/projects/process-nonexistent
10 files changed
+205
-672
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
154 | 154 | | |
155 | 155 | | |
156 | 156 | | |
157 | | - | |
| 157 | + | |
158 | 158 | | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
159 | 174 | | |
160 | 175 | | |
161 | 176 | | |
| |||
388 | 403 | | |
389 | 404 | | |
390 | 405 | | |
391 | | - | |
| 406 | + | |
392 | 407 | | |
393 | 408 | | |
394 | 409 | | |
| |||
520 | 535 | | |
521 | 536 | | |
522 | 537 | | |
523 | | - | |
| 538 | + | |
524 | 539 | | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
525 | 547 | | |
526 | 548 | | |
527 | 549 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
16 | | - | |
17 | | - | |
| 15 | + | |
18 | 16 | | |
19 | 17 | | |
20 | 18 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | | - | |
3 | | - | |
4 | | - | |
5 | | - | |
6 | | - | |
7 | | - | |
8 | | - | |
9 | | - | |
10 | | - | |
11 | | - | |
12 | | - | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
| 1 | + | |
31 | 2 | | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
0 commit comments