delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2024/06/03/09:21:03

DKIM-Filter: OpenDKIM Filter v2.11.0 delorie.com 453DL3tK3782504
Authentication-Results: delorie.com;
dkim=pass (1024-bit key, unprotected) header.d=cygwin.com header.i=@cygwin.com header.a=rsa-sha256 header.s=default header.b=Bz/IUzO3
X-Recipient: archive-cygwin AT delorie DOT com
DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6188D3AA9927
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com;
s=default; t=1717420861;
bh=fEzZ6fRvflP41fA+Bb9xahvLSMltepMggzROXDDGJd0=;
h=Date:Subject:To:References:In-Reply-To:List-Id:List-Unsubscribe:
List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:
From;
b=Bz/IUzO33sBB5eGeaIKBCOntvkvBE07uuvUiOHviI1LnQ0QVcwr0uUT6cEZ50b4X6
M5jGZeJGdjUcgBnGxRqZ4r0hPmK8c47tRSPhO+EsoLKd46e/qs0cR/PWTw2P2B7egB
mafIy3VpTiwh0A0mIjpq9G/1ZHcabmjoCGNB6zg8=
X-Original-To: cygwin AT cygwin DOT com
Delivered-To: cygwin AT cygwin DOT com
DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 985023858430
ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 985023858430
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
X-UI-Sender-Class: 55c96926-9e95-11ee-ae09-1f7a4046a0f6
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 AT cygwin DOT com
References: <d268ca90-3c5b-4de6-9dd5-320ee713283c AT johannesthoma DOT com>
<20240423035104 DOT 85352f8a8d821c0f4d569d18 AT nifty DOT ne DOT jp>
<b71816f0-633c-4eaf-b9d6-955b10e4866a AT johannesthoma DOT com>
<20240423192606 DOT 7b4aa04685afca2525eb5ed3 AT nifty DOT ne DOT jp>
<6dd8a568-88c0-42d5-aa46-b09247cdecec AT johannesthoma DOT com>
<b67fc4f5-3fbb-454a-a0ce-da4f987924dc AT johannesthoma DOT com>
<d00f900a-e70c-4a2b-9570-0d3c9fcd45d2 AT SystematicSW DOT ab DOT ca>
<5ed3b0b8-d4f8-454c-951a-fc7b85a7c302 AT johannesthoma DOT com>
In-Reply-To: <5ed3b0b8-d4f8-454c-951a-fc7b85a7c302@johannesthoma.com>
X-Provags-ID: V03:K1:AUNmPvUFmAbhNXLM4Vh2BhsLGzUSVnFU88Eel+gld2+QcXW6ZKj
z3rRQQM+64OyZOKdXxIF7Z39vM+toQmHTHocWDnUIE/nw3hWEIqN+a86uU/6/HPN1p89rsx
e/95BwL9E1TDmQudJszFcovLFGxJWi/wSZwNfS/RmK7PIA27pf9jX+Z0eO0Trb/a2lDZ52h
PHorZ5NpgekIt63Qoz1Pg==
UI-OutboundReport: notjunk:1;M01:P0:+JRucde4wkk=;XZWYY7Y+BdUOhF5pwMbeXgS/5t2
kfw1LxOeGid0eb7jfeOYOkIIAEPxlQFPn21I4V9OlCfdvxAg2hs/YGnQT2elPUD65Sb9GEAPE
xh1dkTlSCzmnJVYsbRDZZq5or0QakSmqmCCqTbGs0IcOXgfPVcbXZWHyOMz2QBbjQnmS/rx1x
K8s0t3Toq+xtgmsLkjpw9S97ZrPa+4a9Z+ui94bdXuJU1YttH0HsFQX1gi5lyDRP5S+00eFFz
4a166bkYwKP71yrHSM+vaOOUTd9ItlJbkj0yBs1qtKlfbyOv3jJ7Z+KBqk7D/v/t9x4gaaaA6
VmF5aZHxY4DvrskNTu/Y/NmOleH9SEGsQNu4swnZSjKPenKHnRvVp2mIp1zKQshRNP6ifJYi7
MUEEmqctJIqks0T8azRaehsOSG6PYaCo1Otma/KGS2hM0qIh+YqkyNutVPw73qFRpSHdguqXk
+lAnHy9s1C/Dytp4X4oFYhq8xMdgOaDJ2xBoI1Qshz4xrqNyjDJSWSBB8pgTSUIz1wmUNuoVJ
FU+KySrOD9G86u2M06eDtk2rmVeTmp0NPg0QwVeHeA1LMZjHIjkyZ50TCaddowag7VnLoArui
UvQMeYDTo2OaZ75+QAUWba6Jlvq2jG0wgcrRNMLOBQ9yazYfeCox+Yxga4h3QXSSGeUsU4raP
d3CvqOtUQktZhe+8JkQASLAq8nwUvJVKm1mbyabgsVjRzG1pCxttoiA4O4PCVZ18yrQypUgdQ
9fIa4EiZxwZTeC1tPBU1xtGNem6yg7562iYcX0C5ANTcggYPYBptfk=
X-Spam-Status: No, score=-8.9 required=5.0 tests=BAYES_00, DKIM_SIGNED,
DKIM_VALID, DKIM_VALID_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
X-BeenThere: cygwin AT cygwin DOT com
X-Mailman-Version: 2.1.30
List-Id: General Cygwin discussions and problem reports <cygwin.cygwin.com>
List-Archive: <https://cygwin.com/pipermail/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-request AT cygwin DOT com?subject=help>
List-Subscribe: <https://cygwin.com/mailman/listinfo/cygwin>,
<mailto:cygwin-request AT cygwin DOT com?subject=subscribe>
From: Johannes Khoshnazar-Thoma via Cygwin <cygwin AT cygwin DOT com>
Reply-To: Johannes Khoshnazar-Thoma <johannes AT johannesthoma DOT com>
Sender: "Cygwin" <cygwin-bounces+archive-cygwin=delorie DOT com AT cygwin DOT com>

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 <johannes AT johannesthoma DOT com>
Date: Wed, 29 May 2024 17:35:35 +0000
Subject: [PATCH] console: use pseudo random thread_sync_event name

---
  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/console.cc
index 1352482e9..d9c88d245 100644
--- 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", myself->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 = v.tv_usec;
+
+      shared_name (name, CONS_THREAD_SYNC, a_random_number);
        thread_sync_event = 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 = 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
--- 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];
--
2.17.1


-- 
Problem reports:      https://cygwin.com/problems.html
FAQ:                  https://cygwin.com/faq/
Documentation:        https://cygwin.com/docs.html
Unsubscribe info:     https://cygwin.com/ml/#unsubscribe-simple

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019