Skip to content

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

@github-actions

Description

@github-actions
Cygwin: console: fix deadlock in pcon teardown

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: https://github.com/msys2/msys2-runtime/issues/338

msys2/msys2-runtime@01d6c70

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions