Thanks to visit codestin.com
Credit goes to github.com

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.

@github-actions
Copy link
Contributor

github-actions bot commented Oct 16, 2025

CT Test Results

    2 files     72 suites   1h 11m 31s ⏱️
1 685 tests 1 341 ✅ 343 💤 1 ❌
1 938 runs  1 535 ✅ 402 💤 1 ❌

For more details on these failures, see this check.

Results for commit 6b6f7f9.

♻️ 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
@frazze-jobb frazze-jobb self-assigned this Oct 22, 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 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
@frazze-jobb frazze-jobb force-pushed the standard_error_register_race_condition branch from 142867a to 6b6f7f9 Compare October 23, 2025 08:20
@frazze-jobb frazze-jobb added the testing currently being tested, tag is used by OTP internal CI label Oct 23, 2025
@frazze-jobb frazze-jobb changed the base branch from master to maint October 23, 2025 08:22
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 testing currently being tested, tag is used by OTP internal CI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

4 participants