From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mout.kundenserver.de (mout.kundenserver.de [212.227.126.133]) by sourceware.org (Postfix) with ESMTPS id 985023858430 for ; Mon, 3 Jun 2024 13:20:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 985023858430 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=johannesthoma.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=johannesthoma.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 985023858430 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=212.227.126.133 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1717420836; cv=none; b=UtvXxOxcMWvA6DsmBpDbW/i//RmhE2LzSkPqDltpa4hvOLvez4anurKGJeKKL2WZz6c7tLQwJlvNZ1yURpcqB1Q2zWUiKU9wDba/Yq4mDCg+a1vwBymF3rVa5aWyndTSUxMdRNdwe7skA9KaeiT9JCHeWqOOeVXeCgnyNZU15uM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1717420836; c=relaxed/simple; bh=eHJcTzx90iuPr+LW8SSjkbPcixmbp7GgB4JUoPFpCRw=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=mAoZxuIJ5HNHOtYGID/iPx7M0f0v6gQJk6HjoHAP680x5OxqARuEdyadJGnK4P71bWEy+IgVFxv38gv8kZ8QwPi5rdtpPl8fkfLMrurtu2psDCGqHhnXTOH0ekv2b7CPD03HFMjJwklbiJVnrgT9/qBOB/AYxsh0F35gieM2LG4= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=johannesthoma.com; s=s1-ionos; t=1717420833; x=1718025633; i=johannes@johannesthoma.com; bh=LxuJ3RRnn126HfiCEea+sdymbr3VaojiJhyVWAiIPsQ=; h=X-UI-Sender-Class:Message-ID:Date:MIME-Version:Subject:To: References:From:In-Reply-To:Content-Type: Content-Transfer-Encoding:cc:content-transfer-encoding: content-type:date:from:message-id:mime-version:reply-to:subject: to; b=P99FakzzA1iIz3Npl9Wt51y0Y65UWGFe5R9YI5GYmDfSjnSX9OcN638axce7RYD7 +bzEiI0JHt4v4D93wJfBit8LIBDG3pu0SMARo9lc4yKCNEunkfR8vD0yOwtmsl9v3 aJb6GetyhnvPXFCwBqrPdBsFPF37nH0MtjPzEiAI4Fv4gYXE5wf7wjuNQLmCeMTxk O0RlGVv+oZ5wGzVDFeFfTsRLJZHwm4DzL+MDxVPmZLs1nD+UrUL6dtqKTLmdNUE+T /2iZMRHkgndQCaydHoHImPNWIN9LjMrSzDrjAZ+ByhmzopXHEeEX+MwYWOdqbh28S vffzAUegvPWWSo1CBQ== X-UI-Sender-Class: 55c96926-9e95-11ee-ae09-1f7a4046a0f6 Received: from [10.43.10.15] ([62.99.137.214]) by mrelayeu.kundenserver.de (mreue009 [212.227.15.167]) with ESMTPSA (Nemesis) id 1MvbOA-1sUy2h0o46-00yDJj for ; Mon, 03 Jun 2024 15:20:33 +0200 Message-ID: <95442cfe-a87c-4816-b337-b130e481e3f1@johannesthoma.com> Date: Mon, 3 Jun 2024 15:20:32 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: cygwin application hangs on closing console To: cygwin@cygwin.com References: <20240423035104.85352f8a8d821c0f4d569d18@nifty.ne.jp> <20240423192606.7b4aa04685afca2525eb5ed3@nifty.ne.jp> <6dd8a568-88c0-42d5-aa46-b09247cdecec@johannesthoma.com> <5ed3b0b8-d4f8-454c-951a-fc7b85a7c302@johannesthoma.com> From: Johannes Khoshnazar-Thoma In-Reply-To: <5ed3b0b8-d4f8-454c-951a-fc7b85a7c302@johannesthoma.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:AUNmPvUFmAbhNXLM4Vh2BhsLGzUSVnFU88Eel+gld2+QcXW6ZKj z3rRQQM+64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AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Hi List, We did more testing and it looks like the name of the event that signals console master thread start and end is shared between unrelated processes (it uses the console minor which is always (?) 0 when running from a powershell). So since it is a two-state event (as opposed to a semaphore) in theory the following can happen: Process A Process B SetEvent(e) SetEvent(e) Waitforevent(e) Waitforevent(e) The second SetEvent does nothing. As a result the later Waitforevent is stuck (which is what we observe). So the question is: why should this event be used in unrelated cygwin processes? Is there a technical reason we don't understand (yet) for doing that (sharing the event). We patched cygwin to use pseudo random event names (the tm_usec field of gettimeofday()) and the stuckness vanished. So unless there is a reason for sharing the event between cygwin processes this patch should work: From f2e2d125a21487579ecb9173406c6322ee4ecfeb Mon Sep 17 00:00:00 2001 From: Johannes Thoma Date: Wed, 29 May 2024 17:35:35 +0000 Subject: [PATCH] console: use pseudo random thread_sync_event name =2D-- winsup/cygwin/fhandler/console.cc | 9 +++++++-- winsup/cygwin/local_includes/fhandler.h | 1 + 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/winsup/cygwin/fhandler/console.cc b/winsup/cygwin/fhandler/co= nsole.cc index 1352482e9..d9c88d245 100644 =2D-- a/winsup/cygwin/fhandler/console.cc +++ b/winsup/cygwin/fhandler/console.cc @@ -1895,7 +1895,12 @@ debug_printf("myself->pid %d con.owner %d\n", mysel= f->pid, con.owner); if (GetModuleHandle ("ConEmuHk64.dll")) hook_conemu_cygwin_connector (); char name[MAX_PATH]; - shared_name (name, CONS_THREAD_SYNC, get_minor ()); + + struct timeval v; + gettimeofday(&v, NULL); + a_random_number =3D v.tv_usec; + + shared_name (name, CONS_THREAD_SYNC, a_random_number); thread_sync_event =3D CreateEvent(NULL, FALSE, FALSE, name); @@ -1983,7 +1988,7 @@ debug_printf("%s: 1\n", __func__); char name[MAX_PATH]; - shared_name (name, CONS_THREAD_SYNC, get_minor ()); + shared_name (name, CONS_THREAD_SYNC, a_random_number); thread_sync_event =3D OpenEvent (MAXIMUM_ALLOWED, FALSE, name); diff --git a/winsup/cygwin/local_includes/fhandler.h b/winsup/cygwin/local= _includes/fhandler.h index 978d3e514..132dc6477 100644 =2D-- a/winsup/cygwin/local_includes/fhandler.h +++ b/winsup/cygwin/local_includes/fhandler.h @@ -2215,6 +2215,7 @@ public: }; typedef cons_handle_set_t handle_set_t; HANDLE thread_sync_event; + int a_random_number; private: static const unsigned MAX_WRITE_CHARS; static console_state *shared_console_info[MAX_CONS_DEV + 1]; =2D- 2.17.1