Skip to content

console: fix deadlock in pcon teardown#134

Merged
dscho merged 2 commits into
mainfrom
fix-deadlock-in-pcon-teardown
Jun 6, 2026
Merged

console: fix deadlock in pcon teardown#134
dscho merged 2 commits into
mainfrom
fix-deadlock-in-pcon-teardown

Conversation

@dscho
Copy link
Copy Markdown
Member

@dscho dscho commented Jun 5, 2026

When a process inside a pseudo console (pcon) exits, the sequence was:

exit()
-> atexit handlers (including pcon_hand_over_proc)
pcon_hand_over_proc closes parent_pty_input_mutex
-- handle slot now free to be recycled --
-> _exit() -> do_exit() -> close_all_files() -> fhandler_console::close()
set_input_mode() waits on input_mutex <-- hangs

The fix, suggested by Takashi Yano: remove the atexit registration entirely and instead call pcon_hand_over_proc() directly from fhandler_console::close(), after both input_mutex and output_mutex have been closed. By that point close() has already waited for cons_master_thread to exit, so parent_pty_input_mutex is no longer accessed by any other thread and can be safely closed.

This closes git-for-windows/git#6257

When a process inside a pseudo console (pcon) exits, the sequence was:

  exit()
    -> atexit handlers (including pcon_hand_over_proc)
         pcon_hand_over_proc closes parent_pty_input_mutex
         -- handle slot now free to be recycled --
    -> _exit() -> do_exit() -> close_all_files() -> fhandler_console::close()
         set_input_mode() waits on input_mutex  <-- hangs

The fix, suggested by Takashi Yano: remove the atexit registration
entirely and instead call pcon_hand_over_proc() directly from
fhandler_console::close(), after both input_mutex and output_mutex
have been closed.  By that point close() has already waited for
cons_master_thread to exit, so parent_pty_input_mutex is no longer
accessed by any other thread and can be safely closed.

Fixes: msys2/msys2-runtime#338
@dscho dscho self-assigned this Jun 5, 2026
@dscho

This comment was marked as outdated.

Let's synchronize Git for Windows' fork of the MSYS2 runtime with the
MSYS2 upstream, to benefit from the pcon teardown fix.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
@dscho
Copy link
Copy Markdown
Member Author

dscho commented Jun 6, 2026

/open pr

The workflow run was started

@dscho dscho merged commit b4195d6 into main Jun 6, 2026
75 of 92 checks passed
@dscho dscho deleted the fix-deadlock-in-pcon-teardown branch June 6, 2026 18:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[New msys2-runtime version] Cygwin: console: fix deadlock in pcon teardown

2 participants