Repository navigation
vm: Process.exit! skips at_exit, as Kernel#exit! already did - #947
Merged
Merged
Conversation
One word, and it is a two-doors defect. MRI implements Kernel#exit! and
Process.exit! with the SAME C function (rb_f_exit_bang), so they cannot differ.
rbgo defines them separately:
kernel_introspect.go raiseSystemExitImmediate correct
process.go raiseSystemExit the non-immediate helper
So Process.exit! ran the at_exit handlers whose skipping is its entire purpose.
Measured against MRI 4.0.7 through cmd/oracle, on
`at_exit { puts "at_exit ran" }; puts "start"; Process.exit! 4`:
MRI status 4, stdout EMPTY
control status 4, "start\nat_exit ran" (18 bytes)
treatment status 4, "start" ( 6 bytes)
## Why nothing caught it
⛔ The EXIT STATUS was already correct through both helpers. The status is what
an exit test naturally asserts, and it is identical either way: only the at_exit
handlers distinguish raiseSystemExit from raiseSystemExitImmediate. A test that
checks the status passes against the bug.
That is also why the comment above the line now says which half each helper
decides -- the `!` is the whole difference between two adjacent definitions, and
nothing in the call made that visible.
## The test, and the control that makes it mean something
TestProcessExitBangSkipsAtExitLikeKernelExitBang asserts three things:
Process.exit! 4 -> "before" no handler
exit! 4 -> "before" the door that was already right
Process.exit 4 -> "before\nhandler ran" THE CONTROL
⛔ Without the third, an implementation where at_exit never ran at all would
pass the first two. And the second is there so a later change cannot fix one
spelling by breaking the other -- which is how this defect arose.
Proved by mutation: restoring raiseSystemExit turns it red on the
`Process.exit!` arm alone (`got "before\nhandler ran"`), the other two arms
untouched.
## ⚠ What is deliberately NOT fixed here
The treatment still prints `start` where MRI prints nothing. That is a separate
defect and it is named rather than folded in: rbgo does not buffer $stdout at
all -- no bufio anywhere, cmd/rbgo/main.go passes os.Stdout straight through --
while reporting `$stdout.sync == false`. So there is no buffer for exit! to
discard.
#676 carries that measurement, including a correction to my own first diagnosis
of it: I had said "MRI discards the buffer and rbgo flushes it" and offered
`$stdout.sync = true` making both agree as proof. The two engines agreed for
DIFFERENT reasons -- sync made MRI's write immediate, and rbgo's always were --
so that experiment had no treatment arm on the rbgo side and proved nothing.
The choice between buffering as MRI does and reporting sync honestly is on #676
and is not this change's to make.
## Checks
- `gotest` over the whole exit/at_exit family: TestProcessExitFamilyIsPublic,
TestExitBangSkipsAtExitHandlers, TestAtExitExitOverridesTheStatus,
TestForkExitStopsTheChildNotTheProgram, TestSystemExitFamily, TestKernelExit,
TestRunAtExitOneRepanic, TestAtExitErrorSwallowed, TestSimpleCovAtExit and the
new one -- all green.
- `gofmt -l internal/vm` silent.
Refs #676
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
vm: Process.exit! skips at_exit, as Kernel#exit! already did
One word, and it is a two-doors defect. MRI implements Kernel#exit! and
Process.exit! with the SAME C function (rb_f_exit_bang), so they cannot differ.
rbgo defines them separately:
kernel_introspect.go raiseSystemExitImmediate correct
process.go raiseSystemExit the non-immediate helper
So Process.exit! ran the at_exit handlers whose skipping is its entire purpose.
Measured against MRI 4.0.7 through cmd/oracle, on
at_exit { puts "at_exit ran" }; puts "start"; Process.exit! 4:MRI status 4, stdout EMPTY
control status 4, "start\nat_exit ran" (18 bytes)
treatment status 4, "start" ( 6 bytes)
Why nothing caught it
⛔ The EXIT STATUS was already correct through both helpers. The status is what
an exit test naturally asserts, and it is identical either way: only the at_exit
handlers distinguish raiseSystemExit from raiseSystemExitImmediate. A test that
checks the status passes against the bug.
That is also why the comment above the line now says which half each helper
decides -- the
!is the whole difference between two adjacent definitions, andnothing in the call made that visible.
The test, and the control that makes it mean something
TestProcessExitBangSkipsAtExitLikeKernelExitBang asserts three things:
Process.exit! 4 -> "before" no handler
exit! 4 -> "before" the door that was already right
Process.exit 4 -> "before\nhandler ran" THE CONTROL
⛔ Without the third, an implementation where at_exit never ran at all would
pass the first two. And the second is there so a later change cannot fix one
spelling by breaking the other -- which is how this defect arose.
Proved by mutation: restoring raiseSystemExit turns it red on the
Process.exit!arm alone (got "before\nhandler ran"), the other two armsuntouched.
⚠ What is deliberately NOT fixed here
The treatment still prints
startwhere MRI prints nothing. That is a separatedefect and it is named rather than folded in: rbgo does not buffer $stdout at
all -- no bufio anywhere, cmd/rbgo/main.go passes os.Stdout straight through --
while reporting
$stdout.sync == false. So there is no buffer for exit! todiscard.
#676 carries that measurement, including a correction to my own first diagnosis
of it: I had said "MRI discards the buffer and rbgo flushes it" and offered
$stdout.sync = truemaking both agree as proof. The two engines agreed forDIFFERENT reasons -- sync made MRI's write immediate, and rbgo's always were --
so that experiment had no treatment arm on the rbgo side and proved nothing.
The choice between buffering as MRI does and reporting sync honestly is on #676
and is not this change's to make.
Checks
gotestover the whole exit/at_exit family: TestProcessExitFamilyIsPublic,TestExitBangSkipsAtExitHandlers, TestAtExitExitOverridesTheStatus,
TestForkExitStopsTheChildNotTheProgram, TestSystemExitFamily, TestKernelExit,
TestRunAtExitOneRepanic, TestAtExitErrorSwallowed, TestSimpleCovAtExit and the
new one -- all green.
gofmt -l internal/vmsilent.Refs #676
Co-Authored-By: Claude Opus 5 noreply@anthropic.com