You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Kernel#fork exists and runs the block in-process: the 'child' mutates the parent, and exit inside it ends the program #774
rbgo: after fork: $g="CHILD-MUTATED-PARENT" pid_is=100001 mypid=26239
MRI : after fork: $g="parent-value" pid_is=26244 mypid=26241
The "child" overwrote the parent's global; the returned pid is synthetic (100001, counting up) and Process.pid is unchanged, so there is no second process at all. internal/vm/spawn.go states the design openly — "Without an OS fork we run the block in-process" — and the reason is sound: Go's runtime cannot be forked safely.
The problem is not the implementation choice, it is that fork { } silently does something with the opposite guarantee to what it is usually called for.fork is the standard way to isolate untrusted work and to drop privileges; a program that forks for either reason gets neither here, and gets no error either. Process.fork correctly raises NoMethodError, and Process.respond_to?(:fork) is correctly false — it is only the Kernel#fork spelling, which is the one almost every program uses, that pretends.
Two further observations from the same measurement, the second worth more attention than the first:
A SystemExit raised inside the block unwinds the whole program: fork { exit 1 } ends everything, where MRI exits only the child. runForkBlock's recover catches the exec sentinel but not this.
Because the block shares the parent's ENV and working directory, a fork whose block calls Dir.chdir or assigns to ENV — a completely routine thing to do in a child before exec — moves the parent.
Options, from least to most disruptive:
Raise NotImplementedError from Kernel#fork too, matching Process.fork. Honest, and loud at the right moment; breaks programs that currently "work" by accident.
Keep it, but make it not corrupt the parent: run the block with the globals/ENV/cwd saved and restored, and contain SystemExit inside it. Closer to a useful approximation, still not isolation.
Reopened: only half of this was fixed, and the tracker closed it anyway
c4ccb3d (the squash of #806) closed this issue. That was not intended — both
the PR body and the commit said so in as many words:
This does not close #774. An uncaught exception in the block still takes
the parent down, where MRI prints it in the child and exits 1.
A closing keyword elsewhere in the same message (Closes #772) carried the day;
writing "this does NOT close #774" next to a mention of it does not prevent
that. Worth knowing before the next PR that fixes one of two issues.
exit, exit! and abort inside a fork block now stop the "child" and
report its status, instead of ending the whole program at the fork call.
Measured against MRI 4.0.7, with a normally-returning block still 0 as the
control.
What remains open — measured again on v0.3.0
An uncaught exception in the block still takes the parent with it:
MRI prints the exception in the child and exits it 1; the parent carries on
and wait2 reports 1.
The reason it was left rather than done halfway: runForkBlock would have to render the exception the way the top level does, and the renderer that exists
lives in cmd/rbgo, not in internal/vm. Converting it to a status silently
would lose the diagnostic, which is worse than the crash — an embedder would get
a "child" that failed with no indication why.
And the larger point of this issue is untouched
Kernel#fork still does not fork. The block runs in the same process, so it
mutates the parent's globals, ENV and working directory, and returns a
synthetic pid. fork is the standard way to isolate untrusted work and to drop
privileges; a program that forks for either reason gets neither here, and gets
no error either. Process.fork correctly raises NoMethodError — it is the Kernel#fork spelling, the one almost every program uses, that pretends.
The "measured again on v0.3.0" above was written before I had re-run it against
the v0.3.0 binary. Done now, so here is the output rather than the assertion:
=== MRI 4.0.7 === === rbgo v0.3.0 ===
before before
forkraise2.rb:2:in 'block in <main>': forkraise2.rb:2:in 'block in <main>':
boom (RuntimeError) boom (RuntimeError)
from …:2:in 'Kernel#fork' from …:2:in '<main>'
from …:2:in '<main>'
after fork (nothing further)
child status=1
parent alive
exit=0 exit=1
The claim holds. Two details the earlier text did not have:
rbgo exits 1; MRI exits 0, because under MRI only the child failed.
MRI's backtrace carries a from …:2:in 'Kernel#fork' frame that rbgo's does
not. Not worth its own issue, but the two are not byte-identical and I would
rather say so than imply they are.
So the issue holds: the block runs in the parent, mutates its binding, and hands
back an Integer a caller cannot tell from a real pid.
⚠ And one thing on top of it:Kernel#fork exists while Process.fork does
not. MRI has both, and they are the same method. That is this week's recurring
shape — one capability, two doors, one wired — and it is fixable on its own
regardless of what is decided below.
⛔ My first probe reported this issue stale. It asked Process.respond_to?(:fork), got false, and took an "absent" branch without
ever calling fork — a negative produced by the wrong question. Recorded
because the wrong probe looked entirely reasonable.
Why "raise NotImplementedError" is the wrong fix, although it is the one I had written down
I put exactly that in #941's Phase 3, on the reasoning that MRI itself raises NotImplementedError where fork is unavailable, so raising is the faithful
behaviour and an honest absence beats a silent wrong answer.
Reading the consumer first — which is what I should have done before writing the
prescription — says no. The emulation is load-bearing for the headline puppet apply path:
site
what rests on it
spawn.go:20
"the Puppet::Util::Execution.execute path is built on (safe_posix_fork runs a block …)"
spawn.go:203
the STDOUT.reopen(pipe_writer) that safe_posix_fork rides on
io.go:184
a standard stream reopened onto another IO, for that same path
io_descriptors.go:645
descriptor handling specifically around a forked block
socket_dialerr_test.go:101
a test asserting the child's exit isrunForkBlock returning the status
Raising would turn a shipped, advertised capability into a NotImplementedError
in exchange for a conformance criterion. That is a trade for a maintainer to
make, not something to slip in under "parity".
Opt-in. Raise NotImplementedError by default; an embedder that wants
the Puppet path enables the emulation through a VM option. Honest to a
program that did not ask for it, and keeps puppet apply working for the one
that did. Costs an option and a test per door.
A real child process.fork(2) in a Go runtime is not safe — the
runtime's other threads do not survive it — so this means re-executing the
binary with a marker and replaying the block, which changes the semantics
differently (the block cannot close over the parent's heap at all).
My reading is that 2 is the only one that satisfies #941's criterion 3
without removing a feature, but it is a scope decision and I am not taking it
unilaterally.
⚠ Whatever is chosen, the exit! inside a forked block needs its own case: spawn.go:358-361 says a block returning normally counts as a child that exited
0, and exit! inside it currently ends the program, which is the second
half of this issue and is untouched by any of the three.
Correction to my own comment above: the two-door asymmetry is deliberate, documented, and I mischaracterised it
I wrote, an hour ago:
Kernel#fork exists while Process.fork does not. MRI has both, and they are
the same method. That is this week's recurring shape — one capability, two
doors, one wired — and it is fixable on its own regardless of what is decided
below.
That is wrong. README.md:438-443 documents exactly this, with the reason and
the consequence:
There is no Process.fork (Process.respond_to?(:fork) is false) — Go's
runtime cannot be forked safely; spawn is the supported way to start a child. Kernel#fork is a different story: fork { ... }does exist and runs the
block in the same process — see the table under Known divergences, because
code that forks to isolate or to drop privileges gets neither here.
So the asymmetry is a reasoned decision that is published, not an unwired door,
and "fixable on its own" was the wrong frame: adding Process.fork as an alias
of the in-process emulation would make rbgo claim a capability the README
deliberately denies.
⛔ This is the second time in one hour I have been wrong about this issue in
the same direction — first prescribing NotImplementedError without reading the puppet apply path that depends on the emulation, then calling a documented
decision an oversight. Both errors came from reasoning about the code without
reading what already describes it. The measurement in my first comment stands;
the characterisations around it did not.
⛔ One real defect found while checking this, and it is the load-bearing half
The sentence above points the reader at "the table under Known divergences". That table does not exist.git grep -i divergenc over every markdown file
in the repository returns the citation itself and nothing else — no such heading
in README.md, docs/, or any of the CONFORMANCE-*.md files.
That reference is the only place a reader would be told what fork { } actually
does to their program. The sentence names the stake correctly — code that forks
to isolate or to drop privileges gets neither here — and then sends them
somewhere that was never written.
Filing/fixing that is a documentation change rather than part of this issue, and
it is the one part of today's fork work that is unambiguously worth doing
whatever is decided about the semantics: a divergence that is deliberate still
has to be findable.
Two more observables of the in-process fork, measured with a control, and one of them is worse than the binding one
Measured 2026-11-15 through cmd/oracle against MRI 4.0.7, rbgo from main.
This issue's first comment covered x = 99 and the pid; these are what at_exit
and buffered output do, which nothing had listed.
1. The child's buffered output reaches the parent's stream
in child appears under rbgo and not under MRI. In MRI the child is a real
process, its puts sits in its own buffer, and exit! discards it. In rbgo
the block runs in the parent, so the text goes into the shared buffer, and
rbgo's exit! flushes it (the flush half is measured on #676).
2. ⛔ exit! inside the block loses the program's at_exit handlers
rbgo prints no parent at_exit at all, although the program runs to completion
and exits 0.
Isolated by control, because "it did not run" has more than one cause. The
same program with the exit! 0 removed:
MRI (62 bytes)
rbgo (47 bytes)
before fork · in child
before fork · in child
parent at_exit ← the child runs it too
—
after fork · parent at_exit
after fork · parent at_exit
rbgo does run at_exit when the block returns normally and does not when
the block calls exit!. So exit! inside the in-process fork consumes or clears
the registry for the whole program, which is a different thing from "exit
inside it ends the program" as this issue's title puts it: the program does not
end — after fork prints, the status is 0 — it just loses its exit handlers.
That is the more serious of the two. at_exit is where a program removes a PID
file, closes a database handle, flushes a log. A Puppet run whose safe_posix_fork block ends in exit! would skip all of it, silently, with a
zero status.
3. And a third observable, inherent rather than fixable
The control shows MRI printing parent at_exittwice: once in the child,
which inherited the handler through fork(2), and once in the parent. rbgo
prints it once, because there is no second process to inherit anything.
That one is a direct consequence of the in-process emulation rather than a
defect on top of it — no amount of care inside runForkBlock produces a second at_exit run for a child that does not exist. It is listed because it is
observable, and because a test written from MRI's output would otherwise look
like it had found a bug.
Where this leaves the three options from my earlier comment
It sharpens them rather than changing them. Option 1 (keep the emulation, make
the doors agree, document it) now has two more lines to document, and the at_exit one is the kind of divergence that silently skips cleanup — which is
an argument for option 2 (opt-in), since a program that did not ask for an
in-process fork would not expect to lose its exit handlers either.
Still a maintainer's decision, and still not mine to take.
Activity
internal/vm: fork { exit n } stops the child, not the program; three …
tannevaled commentedon Oct 10, 2026
Reopened: only half of this was fixed, and the tracker closed it anyway
c4ccb3d(the squash of #806) closed this issue. That was not intended — boththe PR body and the commit said so in as many words:
A closing keyword elsewhere in the same message (
Closes #772) carried the day;writing "this does NOT close #774" next to a mention of it does not prevent
that. Worth knowing before the next PR that fixes one of two issues.
What IS fixed
exit,exit!andabortinside aforkblock now stop the "child" andreport its status, instead of ending the whole program at the
forkcall.Measured against MRI 4.0.7, with a normally-returning block still 0 as the
control.
What remains open — measured again on v0.3.0
An uncaught exception in the block still takes the parent with it:
MRI prints the exception in the child and exits it 1; the parent carries on
and
wait2reports 1.The reason it was left rather than done halfway:
runForkBlockwould have torender the exception the way the top level does, and the renderer that exists
lives in
cmd/rbgo, not ininternal/vm. Converting it to a status silentlywould lose the diagnostic, which is worse than the crash — an embedder would get
a "child" that failed with no indication why.
And the larger point of this issue is untouched
Kernel#forkstill does not fork. The block runs in the same process, so itmutates the parent's globals,
ENVand working directory, and returns asynthetic pid.
forkis the standard way to isolate untrusted work and to dropprivileges; a program that forks for either reason gets neither here, and gets
no error either.
Process.forkcorrectly raisesNoMethodError— it is theKernel#forkspelling, the one almost every program uses, that pretends.🤖 Generated with Claude Code
tannevaled commentedon Oct 10, 2026
The "measured again on v0.3.0" above was written before I had re-run it against
the v0.3.0 binary. Done now, so here is the output rather than the assertion:
The claim holds. Two details the earlier text did not have:
from …:2:in 'Kernel#fork'frame that rbgo's doesnot. Not worth its own issue, but the two are not byte-identical and I would
rather say so than imply they are.
tannevaled commentedon Nov 15, 2026
Confirmed at the present time — and the obvious fix would break
puppet apply, so it is a decision rather than a defect to patchThe measurement
cmd/oracle, the same program under MRI 4.0.7 and rbgo built frommainatbd5579c1, 2026-11-15:Process.respond_to?(:fork)Kernel.private_method_defined?(:fork)xafter the blockpid.classIntegerIntegerSo the issue holds: the block runs in the parent, mutates its binding, and hands
back an
Integera caller cannot tell from a real pid.⚠ And one thing on top of it:
Kernel#forkexists whileProcess.forkdoesnot. MRI has both, and they are the same method. That is this week's recurring
shape — one capability, two doors, one wired — and it is fixable on its own
regardless of what is decided below.
⛔ My first probe reported this issue stale. It asked
Process.respond_to?(:fork), gotfalse, and took an "absent" branch withoutever calling
fork— a negative produced by the wrong question. Recordedbecause the wrong probe looked entirely reasonable.
Why "raise
NotImplementedError" is the wrong fix, although it is the one I had written downI put exactly that in #941's Phase 3, on the reasoning that MRI itself raises
NotImplementedErrorwhere fork is unavailable, so raising is the faithfulbehaviour and an honest absence beats a silent wrong answer.
Reading the consumer first — which is what I should have done before writing the
prescription — says no. The emulation is load-bearing for the headline
puppet applypath:spawn.go:20Puppet::Util::Execution.executepath is built on (safe_posix_fork runs a block …)"spawn.go:203STDOUT.reopen(pipe_writer)that safe_posix_fork rides onio.go:184io_descriptors.go:645socket_dialerr_test.go:101runForkBlockreturning the statusRaising would turn a shipped, advertised capability into a
NotImplementedErrorin exchange for a conformance criterion. That is a trade for a maintainer to
make, not something to slip in under "parity".
The three ways out, with what each costs
Process.forkas the same method, and say in the docs that rbgo'sforkisin-process. Cheapest; keeps criterion 3 of Functional parity with MRI: the ordered plan, and what each phase is actually blocked on #941 violated on purpose, in
writing.
NotImplementedErrorby default; an embedder that wantsthe Puppet path enables the emulation through a VM option. Honest to a
program that did not ask for it, and keeps
puppet applyworking for the onethat did. Costs an option and a test per door.
fork(2)in a Go runtime is not safe — theruntime's other threads do not survive it — so this means re-executing the
binary with a marker and replaying the block, which changes the semantics
differently (the block cannot close over the parent's heap at all).
My reading is that 2 is the only one that satisfies #941's criterion 3
without removing a feature, but it is a scope decision and I am not taking it
unilaterally.
⚠ Whatever is chosen, the
exit!inside a forked block needs its own case:spawn.go:358-361says a block returning normally counts as a child that exited0, and
exit!inside it currently ends the program, which is the secondhalf of this issue and is untouched by any of the three.
Refs #941
🤖 Generated with Claude Code
tannevaled commentedon Nov 15, 2026
Correction to my own comment above: the two-door asymmetry is deliberate, documented, and I mischaracterised it
I wrote, an hour ago:
That is wrong.
README.md:438-443documents exactly this, with the reason andthe consequence:
So the asymmetry is a reasoned decision that is published, not an unwired door,
and "fixable on its own" was the wrong frame: adding
Process.forkas an aliasof the in-process emulation would make rbgo claim a capability the README
deliberately denies.
⛔ This is the second time in one hour I have been wrong about this issue in
the same direction — first prescribing
NotImplementedErrorwithout reading thepuppet applypath that depends on the emulation, then calling a documenteddecision an oversight. Both errors came from reasoning about the code without
reading what already describes it. The measurement in my first comment stands;
the characterisations around it did not.
⛔ One real defect found while checking this, and it is the load-bearing half
The sentence above points the reader at "the table under Known divergences".
That table does not exist.
git grep -i divergencover every markdown filein the repository returns the citation itself and nothing else — no such heading
in
README.md,docs/, or any of theCONFORMANCE-*.mdfiles.That reference is the only place a reader would be told what
fork { }actuallydoes to their program. The sentence names the stake correctly — code that forks
to isolate or to drop privileges gets neither here — and then sends them
somewhere that was never written.
Filing/fixing that is a documentation change rather than part of this issue, and
it is the one part of today's
forkwork that is unambiguously worth doingwhatever is decided about the semantics: a divergence that is deliberate still
has to be findable.
Refs #941
🤖 Generated with Claude Code
README: a cross-reference to a section that was never written, and a …
tannevaled commentedon Nov 15, 2026
Two more observables of the in-process fork, measured with a control, and one of them is worse than the binding one
Measured 2026-11-15 through
cmd/oracleagainst MRI 4.0.7, rbgo frommain.This issue's first comment covered
x = 99and the pid; these are whatat_exitand buffered output do, which nothing had listed.
The program
before forkbefore forkin childafter forkafter forkparent at_exitTwo differences, and they are separate defects.
1. The child's buffered output reaches the parent's stream
in childappears under rbgo and not under MRI. In MRI the child is a realprocess, its
putssits in its own buffer, andexit!discards it. In rbgothe block runs in the parent, so the text goes into the shared buffer, and
rbgo's
exit!flushes it (the flush half is measured on #676).2. ⛔
exit!inside the block loses the program'sat_exithandlersrbgo prints no
parent at_exitat all, although the program runs to completionand exits 0.
Isolated by control, because "it did not run" has more than one cause. The
same program with the
exit! 0removed:before fork·in childbefore fork·in childparent at_exit← the child runs it tooafter fork·parent at_exitafter fork·parent at_exitrbgo does run
at_exitwhen the block returns normally and does not whenthe block calls
exit!. Soexit!inside the in-process fork consumes or clearsthe registry for the whole program, which is a different thing from "
exitinside it ends the program" as this issue's title puts it: the program does not
end —
after forkprints, the status is 0 — it just loses its exit handlers.That is the more serious of the two.
at_exitis where a program removes a PIDfile, closes a database handle, flushes a log. A Puppet run whose
safe_posix_forkblock ends inexit!would skip all of it, silently, with azero status.
3. And a third observable, inherent rather than fixable
The control shows MRI printing
parent at_exittwice: once in the child,which inherited the handler through
fork(2), and once in the parent. rbgoprints it once, because there is no second process to inherit anything.
That one is a direct consequence of the in-process emulation rather than a
defect on top of it — no amount of care inside
runForkBlockproduces a secondat_exitrun for a child that does not exist. It is listed because it isobservable, and because a test written from MRI's output would otherwise look
like it had found a bug.
Where this leaves the three options from my earlier comment
It sharpens them rather than changing them. Option 1 (keep the emulation, make
the doors agree, document it) now has two more lines to document, and the
at_exitone is the kind of divergence that silently skips cleanup — which isan argument for option 2 (opt-in), since a program that did not ask for an
in-process fork would not expect to lose its exit handlers either.
Still a maintainer's decision, and still not mine to take.
Refs #676, #941
🤖 Generated with Claude Code