Skip to content

Conversation

NelsonVides
Copy link
Contributor

@NelsonVides NelsonVides commented Oct 16, 2025

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/0 function had a race condition:

  1. spawn(fun server/0) - creates process, starts executing immediately
  2. register(?NAME, Id) - parent registers the spawned process
  3. server() calls prim_tty:init() - may execute before step 2

When prim_tty:init/1 spawns writer/reader processes, they call set_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/2 call into the spawned process itself, ensuring it completes before prim_tty:init/1 is 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.

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 erlang#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/0 function had a race condition:
1. spawn(fun server/0) - creates process, starts executing immediately
2. register(?NAME, Id) - parent registers the spawned process
3. server() calls prim_tty:init() - may execute before step 2

When prim_tty:init/1 spawns writer/reader processes, they call
set_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/2 call into the spawned process itself,
ensuring it completes before prim_tty:init/1 is called. This eliminates
the race condition entirely.

Closes erlang#10174
Copy link
Contributor

github-actions bot commented Oct 16, 2025

CT Test Results

    2 files     72 suites   1h 7m 9s ⏱️
1 685 tests 1 341 ✅ 344 💤 0 ❌
1 937 runs  1 535 ✅ 402 💤 0 ❌

Results for commit 142867a.

♻️ This comment has been updated with latest results.

To speed up review, make sure that you have read Contributing to Erlang/OTP and that all checks pass.

See the TESTING and DEVELOPMENT HowTo guides for details about how to run test locally.

Artifacts

// Erlang/OTP Github Action Bot

@rickard-green rickard-green added the team:VM Assigned to OTP team VM label Oct 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

team:VM Assigned to OTP team VM

Projects

None yet

Development

Successfully merging this pull request may close these issues.

prim_tty:init(#{}). does not work on macOS

2 participants