Re: [PATCH] Cygwin: console: Fix deadlock in console teardown that arises from pcon

Takashi Yano <[email protected]> Fri, 29 May 2026 11:36:49 +0900
Newsgroups gmane.os.cygwin.patches
Message-ID <[email protected]>
On Thu, 28 May 2026 15:38:46 +0200 (CEST)
Johannes Schindelin wrote:
> Hi Takashi,
> 
> On Fri, 22 May 2026, Takashi Yano wrote:
> 
> > When a console process originating from a pseudo console exits, the
> > current sequence is as follows:
> > 
> >   1) atexit handlers (pcon_handover_proc) called. This also closes
> >      parent_pty_input_mutex which is introduced by the commit
> >      c4fb720afcf1.
> >   2) close_all_files() is called via _exit(). This terminates
> >      cons_master_thread.
> > 
> > parent_pty_input_mutex is referenced in cons_master_thread, so
> > cons_master_thread may still use the mutex after it has been closed.
> > This can lead to undesired behaviour, including a deadlock. Instead
> > of registering pcon_hand_over_proc() as an atexit handler, this
> > patch calls pcon_handover_proc() at a point in fhandler_console::close
> > where cons_master_thread has already terminated, ensuring that no
> > other thread accesses the mutex.
> 
> Thank you so much for this excellent commit message, which motivates the
> patch well and preempts all the questions I would have asked about the
> code changes.
> 
> The entire patch looks good to me!

Thanks for the review. Pushed.

-- 
Takashi Yano <[email protected]>