From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qk1-x730.google.com (mail-qk1-x730.google.com [IPv6:2607:f8b0:4864:20::730]) by sourceware.org (Postfix) with ESMTPS id 3150D3858D39 for ; Sun, 26 Dec 2021 15:25:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 3150D3858D39 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-qk1-x730.google.com with SMTP id i187so10327481qkf.5 for ; Sun, 26 Dec 2021 07:25:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=DQadlf/WdevlSONPDYLZU5djcO4OMEepr3xGikNH8z8=; b=mKB9CUImPJXuoueFviwt93J7PrpZnOkfPzupney0QsYcA1jWbiwmdVipiphpflKJco QGLo6VUCODR1+ygtImiSkfSr5kVkwuVNi/94VhlhP+50OMrgKv2zA1B4BHldC1hnAr0Z xbdvPLx3hwG1jkwFSKUKCu60eZi+14xZxO8/IJNTC34qoCC03lAgTaMjpMYgWWuC87CM XY3z7HarFNx9yuPOkiVMbl3U1cSYk2U3Zthu7g48+Znr7ViGWAvcCOh6af8cbdvwqkUd 7WjC5fRdCr28Y7qyQ07QrIu9gyMIltf6h/DT6QSGxUTlk6ijAmnUzAV3SLcBc7lnbkTA FrFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=DQadlf/WdevlSONPDYLZU5djcO4OMEepr3xGikNH8z8=; b=KThMYtvtfJL0OawPUjflCBqJenMU6ysLaOi5HziEG8p2ZPETf6K2ArByyLe3naeEWl SWTbmy1BWaVgDg1ZCNNPiOKLhkHUxewv9WBgOKsv3MVs8/O7adD0vGO16M7/tXFoITo7 p3VrUmZ6mW9u1tC+bU7fMoUm5l3C0qsUDuJ8mtdxK96KpXwcKNhjvQbH1NjhS/a2R90u 1irsBEHZ7Ud62FCFcYkS2K0PbVcea7pS1nGHfqPDUfwU6umNk/l1OoMbfZfzKXxT3z4N ZEMrDGQT8o5/hZrCKvtQgGfHDOJ7HHAIXMoNMNO0qsvzAFf7RrxlDOWDbN61Bm8jA5o1 wQMg== X-Gm-Message-State: AOAM532j25V1kzLHaGppmT2ejKl2FJdJkLfW0SWJemV5KCbGwhqtmROg hyHCGGOhIrl9z8sFKtu/fyxT+tgX+is= X-Google-Smtp-Source: ABdhPJwaNNH2j1nWmj5/z24hR7YdcyElIeXh/xmm0GRKGgptkcg5B6wD09sRwP3ZDKMSGbfyzPq8oA== X-Received: by 2002:a37:a1cd:: with SMTP id k196mr9282486qke.172.1640532344461; Sun, 26 Dec 2021 07:25:44 -0800 (PST) Received: from davidm-laptop (hlfxns018gw-134-41-172-106.dhcp-dynamic.fibreop.ns.bellaliant.net. [134.41.172.106]) by smtp.gmail.com with ESMTPSA id s3sm11581473qkp.93.2021.12.26.07.25.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Dec 2021 07:25:43 -0800 (PST) From: David McFarland To: Takashi Yano Cc: cygwin-developers@cygwin.com Subject: Re: deadlock on console mutex in gdb References: <20211223054409.610242feb0e96199904b3c9e@nifty.ne.jp> <20211223182440.e37115a4493516aca7ed7873@nifty.ne.jp> <87mtkribfg.fsf@gmail.com> Date: Sun, 26 Dec 2021 11:25:40 -0400 In-Reply-To: (David McFarland's message of "Thu, 23 Dec 2021 15:28:58 -0400") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (cygwin) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-9.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, WEIRD_PORT autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: cygwin-developers@cygwin.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Cygwin core component developers mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 26 Dec 2021 15:25:47 -0000 David McFarland writes: > I've also been hitting another console related deadlock, even when > there's no debugger involved: So I tried to fix this one by doing this: >From a66d334577217f178a841f006e295a9b8e50c677 Mon Sep 17 00:00:00 2001 From: David McFarland Date: Thu, 23 Dec 2021 16:12:47 -0400 Subject: [PATCH] tty: create attach_mutex in static constructor --- winsup/cygwin/fhandler_tty.cc | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/winsup/cygwin/fhandler_tty.cc b/winsup/cygwin/fhandler_tty.cc index c425c158b..36262dbb9 100644 --- a/winsup/cygwin/fhandler_tty.cc +++ b/winsup/cygwin/fhandler_tty.cc @@ -58,7 +58,7 @@ struct pipe_reply { }; /* Mutex for AttachConsole()/FreeConsole() */ -HANDLE attach_mutex; +HANDLE attach_mutex = CreateMutex (&sec_none, FALSE, NULL); bool __acquire_attach_mutex (const char *fn, int ln, DWORD t) { @@ -77,8 +77,6 @@ void __release_attach_mutex (const char *fn, int ln) assert(r); } -static LONG master_cnt = 0; - inline static bool pcon_pid_alive (DWORD pid); DWORD @@ -2122,8 +2120,6 @@ fhandler_pty_master::close () master_fwd_thread->terminate_thread (); } } - if (InterlockedDecrement (&master_cnt) == 0) - CloseHandle (attach_mutex); /* Check if the last master handle has been closed. If so, set input_available_event to wake up potentially waiting slaves. */ @@ -3002,9 +2998,6 @@ fhandler_pty_master::setup () if (!(pcon_mutex = CreateMutex (&sa, FALSE, buf))) goto err; - if (InterlockedIncrement (&master_cnt) == 1) - attach_mutex = CreateMutex (&sa, FALSE, NULL); - /* Create master control pipe which allows the master to duplicate the pty pipe handles to processes which deserve it. */ __small_sprintf (buf, "\\\\.\\pipe\\cygwin-%S-pty%d-master-ctl", -- 2.32.0 Unfortunately I seem to have another deadlock when using this patch. With the above patch applied, if I just open bash and hold down ^C, it will deadlock pretty quickly. It's possible this is an exiting problem that isn't normally noticed because bash never opens the PT. The threads involved are: Thread 1 (Thread 14700.0x3804): #0 0x00007ffca30ed8c4 in ntdll!ZwWaitForMultipleObjects () from /cygdrive/c/WINDOWS/SYSTEM32/ntdll.dll #1 0x00007ffca0dbcb20 in WaitForMultipleObjectsEx () from /cygdrive/c/WINDOWS/System32/KERNELBASE.dll #2 0x00007ffca0dbca1e in WaitForMultipleObjects () from /cygdrive/c/WINDOWS/System32/KERNELBASE.dll #3 0x000000018012f89e in select_stuff::wait (this=0xffffb4b0, readfds=0xffffb720, writefds=0xffffb620, exceptfds=0xffffb630, us=-1) at ../../../../winsup/cygwin/select.cc:419 #4 0x000000018012ee17 in select (maxfds=1, readfds=0xffffb720, writefds=0xffffb620, exceptfds=0xffffb630, us=-1) at ../../../../winsup/cygwin/select.cc:192 #5 0x000000018012e967 in pselect (maxfds=1, readfds=0xffffb720, writefds=0x0, exceptfds=0x0, to=0x0, set=0x3fd45b890 ) at ../../../../winsup/cygwin/select.cc:120 #6 0x00000001801a761b in _sigfe () at sigfe.s:37 #7 0x00000003fd43e698 in rl_getc () from /usr/bin/cygreadline7.dll #8 0x00000003fd43eecc in rl_read_key () from /usr/bin/cygreadline7.dll #9 0x00000003fd421ef3 in readline_internal_char () from /usr/bin/cygreadline7.dll #10 0x00000003fd422905 in readline () from /usr/bin/cygreadline7.dll #11 0x000000010040265d in reader_loop () #12 0x0000000100404723 in decode_prompt_string () #13 0x00000001004074ac in read_secondary_line () #14 0x000000010040aa97 in yyparse () #15 0x0000000100401b92 in parse_command () #16 0x0000000100401c96 in read_command () #17 0x0000000100401ec4 in reader_loop () #18 0x000000010047c3ba in main () Thread 6 (Thread 14700.0x1e9c): #0 0x00007ffca30ecdf4 in ntdll!ZwWaitForSingleObject () from /cygdrive/c/WINDOWS/SYSTEM32/ntdll.dll #1 0x00007ffca0d91a5e in WaitForSingleObjectEx () from /cygdrive/c/WINDOWS/System32/KERNELBASE.dll #2 0x00000001800c13b8 in __acquire_attach_mutex (fn=0x1802c59b8 "virtual int fhandler_console::tcflush(int)", ln=1574, t=4294967295) at ../../../../winsup/cygwin/fhandler_tty.cc:67 #3 0x0000000180074fa7 in fhandler_console::tcflush (this=0x1803b6760, queue=0) at ../../../../winsup/cygwin/fhandler_console.cc:1574 #4 0x00000001800c025c in fhandler_termios::sigflush (this=0x1803b6760) at ../../../../winsup/cygwin/fhandler_termios.cc:503 #5 0x00000001800bec92 in tty_min::kill_pgrp (this=0x180000000, sig=2) at ../../../../winsup/cygwin/fhandler_termios.cc:131 #6 0x0000000180070a62 in fhandler_console::cons_master_thread (p=0x26acb70, ttyp=0x180000000) at ../../../../winsup/cygwin/fhandler_console.cc:253 #7 0x0000000180070555 in cons_master_thread (arg=0x1803b63e0) at ../../../../winsup/cygwin/fhandler_console.cc:173 #8 0x000000018004657c in cygthread::callfunc (this=0x180278278 , issimplestub=false) at ../../../../winsup/cygwin/cygthread.cc:48 #9 0x0000000180046724 in cygthread::stub (arg=0x180278278 ) at ../../../../winsup/cygwin/cygthread.cc:91 #10 0x00000001800473b6 in _cygtls::call2 (this=0x26ace00, func=0x180046582 , arg=0x180278278 , buf=0x26acce0) at ../../../../winsup/cygwin/cygtls.cc:55 #11 0x000000018004735b in _cygtls::call (func=0x180046582 , arg=0x180278278 ) at ../../../../winsup/cygwin/cygtls.cc:42 #12 0x00000001800df5b2 in threadfunc_fe (arg=0x180278278 ) at ../../../../winsup/cygwin/init.cc:30 #13 0x00007ffca2ae7034 in KERNEL32!BaseThreadInitThunk () from /cygdrive/c/WINDOWS/System32/KERNEL32.DLL #14 0x00007ffca30a2651 in ntdll!RtlUserThreadStart () from /cygdrive/c/WINDOWS/SYSTEM32/ntdll.dll #15 0x0000000000000000 in ?? () Thread 9 (Thread 14700.0x183c): #0 0x00007ffca30ecdf4 in ntdll!ZwWaitForSingleObject () from /cygdrive/c/WINDOWS/SYSTEM32/ntdll.dll #1 0x00007ffca0d91a5e in WaitForSingleObjectEx () from /cygdrive/c/WINDOWS/System32/KERNELBASE.dll #2 0x000000018007bb0c in fhandler_console::__acquire_input_mutex (this=0x1803b7420, fn=0x1802e1a20 "int peek_console(select_record*, bool)", ln=1133, ms=4294967295) at ../../../../winsup/cygwin/fhandler_console.cc:3726 #3 0x0000000180131b3f in peek_console (me=0x8000ac530) at ../../../../winsup/cygwin/select.cc:1133 #4 0x0000000180131ce3 in thread_console (arg=0x800075610) at ../../../../winsup/cygwin/select.cc:1173 #5 0x000000018004657c in cygthread::callfunc (this=0x1802782d0 , issimplestub=false) at ../../../../winsup/cygwin/cygthread.cc:48 #6 0x0000000180046724 in cygthread::stub (arg=0x1802782d0 ) at ../../../../winsup/cygwin/cygthread.cc:91 #7 0x00000001800473b6 in _cygtls::call2 (this=0x2cbce00, func=0x180046582 , arg=0x1802782d0 , buf=0x2cbcce0) at ../../../../winsup/cygwin/cygtls.cc:55 #8 0x000000018004735b in _cygtls::call (func=0x180046582 , arg=0x1802782d0 ) at ../../../../winsup/cygwin/cygtls.cc:42 #9 0x00000001800df5b2 in threadfunc_fe (arg=0x1802782d0 ) at ../../../../winsup/cygwin/init.cc:30 #10 0x00007ffca2ae7034 in KERNEL32!BaseThreadInitThunk () from /cygdrive/c/WINDOWS/System32/KERNEL32.DLL #11 0x00007ffca30a2651 in ntdll!RtlUserThreadStart () from /cygdrive/c/WINDOWS/SYSTEM32/ntdll.dll #12 0x0000000000000000 in ?? () Thread 6 holds input_mutex from cons_master_thread, and thread 9 holds attach_mutex from peek_console. Perhaps it would make sense for peek_console to hold attach_mutex only around the call to PeekConsoleInputW?