Fix race condition in standard_error process registration #10290
+2
−3
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.
Fix a race condition where the standard_error process could call prim_tty:init/1 before being registered, causing a crash when prim_tty's writer and reader processes attempt to derive their own registered names from the parent process.
The issue was introduced in commit ead7424 (PR #9116), which changed prim_tty's reader and writer processes to dynamically derive their registered names from their parent process name (e.g.,
standard_error->standard_error_reader,standard_error_writer). This was done to support multiple TTY instances (stdout and stderr) with distinct process names.However, the
standard_error:start/0function had a race condition:spawn(fun server/0)- creates process, starts executing immediatelyregister(?NAME, Id)- parent registers the spawned processserver()callsprim_tty:init()- may execute before step 2When
prim_tty:init/1spawns writer/reader processes, they callset_name(Parent, Postfix)which does:erlang:process_info(Parent, registered_name)If this executes before the parent completes registration, it returns [] instead of {registered_name, standard_error}, causing a pattern match failure: "no match of right hand side value: []" at prim_tty.erl:674.
The fix moves the
register/2call into the spawned process itself, ensuring it completes beforeprim_tty:init/1is called. This eliminates the race condition entirely.Closes #10174
For the record, this bug prevents the VM from starting altogether in a dockerised deployment at my workplace and we've had to stick to 27.x so far.