public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Johannes Khoshnazar-Thoma <johannes@johannesthoma.com>
To: cygwin@cygwin.com
Subject: Re: cygwin application hangs on closing console
Date: Mon, 1 Jul 2024 13:47:56 +0200	[thread overview]
Message-ID: <fb960e5d-ccdd-474b-a046-5178563d4200@johannesthoma.com> (raw)
In-Reply-To: <20240629003209.d0bd3cc2961891fb69b55b35@nifty.ne.jp>

Hi Takashi Yano,

Thank you for your reply, comments inline.

Am 28.06.24 um 17:32 schrieb Takashi Yano via Cygwin:
> On Fri, 28 Jun 2024 21:17:26 +0900
> Takashi Yano wrote:
>> Sorry for very late replay.
No problem we are all sometimes very busy :)

>>
>> On Mon, 3 Jun 2024 15:20:32 +0200
>> Johannes Khoshnazar-Thoma wrote:
>>> 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)
>>
>> This should not happen. Master thread is unique to console.
>> get_minor() number is always 0 for the first opened console.
>> If you open another powershell window and start cygwin process
>> while the first cygwin process is still active, the get_minor()
>> returns 1.
>>
>> Waiting for thread_sync_event is executed only
>>    if (shared_console_info[unit] && con.owner == myself->pid)
>> con.owner is in the shared memory which is shared among all
>> processes started in the same console. Therefore, only the
>> one process start to wait the event.
>>
>>> 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:
>>
>> Do you really confirm that your patch resolves the issue?
>> If so, the cause might be some kind of race issue.
>
This patch solved the issue for our case. It was running for
3 days (instead of about 30 minutes) and the hang in console
close did not trigger.

Note that the hang does not happen when just running cygwin
applications via terminal windows (like cmd, powershell and
MinTTY). It triggers however when a cygwin application is
run both as a service (I think as SYSTEM account, but I
can ask again) and from a terminal window.

> There was similar bug in cygwin 3.5.1, however, it has been
> already fixed in 3.5.3.
> https://cygwin.com/git/?p=newlib-cygwin.git;a=commitdiff;h=fc5e9525453fea7c27b0e13635ae54abaa0db69d
>
> I believe your problem is reproducible with 3.5.3. Right?
>
Yes it is. We did long running tests and it is reproducible
with 3.5.3. I also did tests that force the minor being the
same for two cygwin processes (by patching the source code)
and the hang also triggers (after a few minutes).

So can it be that separate cygwin processes can have the
same minor? For example when on is started as a service
and the other is started interactively?

Could you maybe point to the place in the cygwin (winsup)
source code where the minor is allocated?

Thanks again for your hard work on cygwin.

Best regards,

- Johannes

  reply	other threads:[~2024-07-01 11:47 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-22 12:50 Johannes Khoshnazar-Thoma
2024-04-22 18:51 ` Takashi Yano
2024-04-23  9:20   ` Johannes Khoshnazar-Thoma
2024-04-23 10:26     ` Takashi Yano
2024-05-15 15:37       ` Johannes Khoshnazar-Thoma
2024-05-15 15:48         ` Johannes Khoshnazar-Thoma
2024-05-15 20:24           ` Brian Inglis
2024-05-21 16:23             ` Johannes Khoshnazar-Thoma
2024-06-03 13:20               ` Johannes Khoshnazar-Thoma
2024-06-28 12:17                 ` Takashi Yano
2024-06-28 15:32                   ` Takashi Yano
2024-07-01 11:47                     ` Johannes Khoshnazar-Thoma [this message]
2024-07-01 13:20                       ` Takashi Yano
2024-07-02 10:45                         ` Takashi Yano
2024-07-03 14:09                           ` Takashi Yano
2024-07-03 14:16                             ` Johannes Khoshnazar-Thoma
2024-07-01 13:36                       ` Takashi Yano
2024-05-16  9:14           ` Takashi Yano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=fb960e5d-ccdd-474b-a046-5178563d4200@johannesthoma.com \
    --to=johannes@johannesthoma.com \
    --cc=cygwin@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).