Commit 6b6f7f9
Fix race condition in standard_error process registration
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 #101741 parent b2e2bc4 commit 6b6f7f9
1 file changed
+2
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
65 | | - | |
66 | | - | |
67 | | - | |
| 65 | + | |
68 | 66 | | |
69 | 67 | | |
70 | 68 | | |
| 69 | + | |
71 | 70 | | |
72 | 71 | | |
73 | 72 | | |
| |||
0 commit comments