Repository navigation
fix(stdlib): read values thrown by gen_server callbacks as returns - #106
Merged
Merged
Conversation
A server whose handle_call/3 throws its answer, such as {reply, Reply, State}, now answers the caller and keeps running, as in standard Erlang.
A server whose handle_cast/2 or handle_info/2 throws {noreply, State} keeps running with its new state, and one that throws {stop, ...} shuts down cleanly through its terminate/2 function.
A value thrown by terminate/2 no longer changes the reason the server gives for stopping.
gen_server:call/2,3 no longer leaves a stray 'DOWN' notice in the caller's mailbox when the server stops right after answering.
A real error in a callback still crashes the server, as before.
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.
Why
Erlang programs build long-running servers on gen_server, which calls the program's own functions (callbacks) for each request; standard Erlang lets a callback hand back its answer with throw instead of return, but Nera's built-in gen_server crashed the server when a callback did that.
What changed
Before and after
Before: Natively, a server crashed whenever a callback threw its answer, so callers got a crash instead of the answer and later requests failed: 0 of 13 such cases in a per-case probe behaved as in standard Erlang (BEAM OTP 29).
After: All 13 cases now behave as in standard Erlang; the one difference left in the probe, terminate/2 not running after a real error, predates this change.
The change is in the built-in server library, which has no screen; native and BEAM transcripts show it.
Checked
How it was checked
nera test gen_server_thrown_return, 10 runs with default schedulers and 10 with NERA_SCHEDULERS=1
erlc tests/gen_server_thrown_return.erl and gen_server_thrown_return:test() on BEAM OTP 29, 10 runs
cargo build --release --locked -p nera-runtime, then -p nera, then the workspace
cargo clippy --workspace --all-targets --locked -- -D warnings
cargo test --workspace --locked --no-fail-fast
python3 scripts/test-allocator-config.py
./target/release/nera test -j 1 --timeout 30
python3 scripts/test-stacktrace-order.py
Risk
Risk above low: Blast radius, medium — Every gen_server request, message and stop now runs through the changed path
Full risk assessment
Not done
Four older differences from standard Erlang remain and are tracked separately: terminate/2 after a real error, the bad_return_value reason, whether a stop answer comes before terminate/2, and call timeout reasons.