Skip to content

Fix bugs causing hangs - #368

Merged
dscho merged 3 commits into
msys2:msys2-3.6.10from
dscho:try-console-mode-and-owner-exit
Sep 25, 2026
Merged

dscho merged 3 commits into
msys2:msys2-3.6.10from
dscho:try-console-mode-and-owner-exit

Conversation

@dscho

@dscho dscho commented Sep 24, 2026 •

Copy link
Copy Markdown
Collaborator

This Pull Request backports three changes. The first one is a prerequisite for the second, and the third is also needed to fix those bugs that caused hangs that I first saw reported in msys2/MSYS2-packages#6445:

  1. c892dfe93e: the complete prerequisite, including the companion dtable.cc standard-handle change.
  2. 92c1e00a38: console-mode v18, including reconciliation on signal and read-retry paths.
  3. c770e1b9fa: owner-exit v5, including the processed-input fallback for an unavailable console master.

I verified that these patches are enough to address the hangs demonstrated by the reproducer provided in #351.

This fixes #351

tyan0 and others added 3 commits September 13, 2026 20:53
Currently, when cygwin app is launched, the console input mode is
set to tty::cygwin, even if the stdin is not a console. However,
it is not necessary because the cygwin app does not use stdin.
This also applies to stdout and stderr.

With this patch, the console mode is set only when std{in,out,err}
is a console for the cygwin app for better coexistence with non-
cygwin apps.

This is a prerequisite for the experimental backport of Takashi Yano's
v15 console-mode patch to msys2-3.6.10. The release branch's later,
already-applied suspension-before-mode ordering is preserved.

(cherry picked from commit bbd3710)
Assisted-by: GPT-6
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Previously, if two non-cygwin apps are started and one of them
exits first, the other one lost appropriate console mode, since
the first one restored it to tty::cygwin. This patch counts the
active console process whose pgid is pgid of the tty and if the
result is zero (means the last non-cygwin foreground process),
restore console mode. To avoid race issue between apps modifying
console mode simultaneously, this patch also introduce a mutex
named `cons_mode_mutex`.

Known limitation:
In the case of non-overlayed spawn, there still exists a small
window in which another non-cygwin process may restore tty::cygwin
mode even though new non-cygwin app is about to start.

In addition:
Avoid the cleanup/startup deadlock: cleanup can hold `cons_mode_mutex`
while waiting for a console master that a new owner cannot start until
acquiring that mutex. Startup must precede the mode-mutex wait without
changing the handshake or mode serialization.

Backport the complete upstream v18 patch after the prerequisite:
https://inbox.sourceware.org/cygwin-patches/20260919004709.26360-1-takashi.yano@nifty.ne.jp/
Adapt only the three existing msys2-3.6.10 preimage/context spellings.

Fixes: 48285aa ("Cygwin: console: Fix handling of Ctrl-S in Win7.")
Co-authored-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Reviewed-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Assisted-by: GPT-6
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
With the commit 733d5a9 ("Cygwin: console: Ensure the master
thread runs only when it is supposed to"), the process which calls
set_disable_master_thread() hangs if the con.owner already exited,
because set_disable_master_thread() waits for cons_master_thread
accepting the status change and reflecting the current status to
master_thread_suspended. With this patch, set_disable_master_thread()
is aborted if the owner process no longer exists to avoid this
hang.

Backport the complete upstream v5 patch unchanged after v18:
https://inbox.sourceware.org/cygwin-patches/20260923223230.3504-1-takashi.yano@nifty.ne.jp/

Addresses: https://cygwin.com/pipermail/cygwin/2026-September/260037.html
Fixes: 733d5a9 ("Cygwin: console: Ensure the master thread runs only when it is supposed to")
Reported-by: Jay Libove Alzina <libove@felines.org>
Co-authored-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Reviewed-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Assisted-by: GPT-6
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
@dscho
dscho marked this pull request as ready for review September 24, 2026 12:06
@dscho
dscho merged commit c770e1b into msys2:msys2-3.6.10 Sep 25, 2026
9 checks passed
@dscho
dscho deleted the try-console-mode-and-owner-exit branch September 25, 2026 15:26
lazka added a commit to msys2/MSYS2-packages that referenced this pull request Sep 26, 2026
* msys2-runtime: Fix bugs causing hangs

This Pull Request backports three changes. The first one is a prerequisite for the second, and the third is also needed to fix those bugs that caused hangs that I first saw reported in #6445:

1. `c892dfe93e`: the [complete prerequisite](cygwin/cygwin@bbd3710), including the companion `dtable.cc` standard-handle change.
2. `92c1e00a38`: [console-mode v18](https://inbox.sourceware.org/cygwin-patches/20260919004709.26360-1-takashi.yano@nifty.ne.jp/), including reconciliation on signal and read-retry paths.
3. `c770e1b9fa`: [owner-exit v5](https://inbox.sourceware.org/cygwin-patches/20260923223230.3504-1-takashi.yano@nifty.ne.jp/), including the processed-input fallback for an unavailable console master.

I verified that these patches are enough to address the hangs demonstrated by the reproducer provided in msys2/msys2-runtime#351.

This fixes msys2/msys2-runtime#351

This corresponds to msys2/msys2-runtime#368

* msys2-runtime: fix pkgrel

Ooops! My script has a bug!

Co-authored-by: Christoph Reiter <reiter.christoph@gmail.com>

---------

Co-authored-by: Christoph Reiter <reiter.christoph@gmail.com>
github-actions Bot pushed a commit to cygapiss/msys2-apiss that referenced this pull request Sep 26, 2026
* msys2-runtime: Fix bugs causing hangs

This Pull Request backports three changes. The first one is a prerequisite for the second, and the third is also needed to fix those bugs that caused hangs that I first saw reported in msys2/MSYS2-packages#6445:

1. `c892dfe93e`: the [complete prerequisite](cygwin/cygwin@bbd3710), including the companion `dtable.cc` standard-handle change.
2. `92c1e00a38`: [console-mode v18](https://inbox.sourceware.org/cygwin-patches/20260919004709.26360-1-takashi.yano@nifty.ne.jp/), including reconciliation on signal and read-retry paths.
3. `c770e1b9fa`: [owner-exit v5](https://inbox.sourceware.org/cygwin-patches/20260923223230.3504-1-takashi.yano@nifty.ne.jp/), including the processed-input fallback for an unavailable console master.

I verified that these patches are enough to address the hangs demonstrated by the reproducer provided in msys2/msys2-runtime#351.

This fixes msys2/msys2-runtime#351

This corresponds to msys2/msys2-runtime#368

* msys2-runtime: fix pkgrel

Ooops! My script has a bug!

Co-authored-by: Christoph Reiter <reiter.christoph@gmail.com>

---------

Co-authored-by: Christoph Reiter <reiter.christoph@gmail.com>

Source: msys2/MSYS2-packages@bca80c8
dscho added a commit to git-for-windows/msys2-runtime that referenced this pull request Sep 26, 2026
In the MSYS2 project, there were several reports of newly-introduced
hangs, e.g. msys2/msys2-runtime#351 and
msys2/MSYS2-packages#6445 (comment).
It took a good while to figure out how to fix this properly, with two
separate fixes needing 18 and 5 iterations, respectively, on the
cygwin-patches mailing list.

This branch merges [MSYS2 runtime PR
#368](msys2/msys2-runtime#368). The sole
`dtable.cc` conflict preserves GFW's pcon-backed PTY detection and
genuine console handles.

Separately, tests running in CI builds are added that replicate the
reproducer of issue 351 and a separate Ctrl+C test that covers
[Takashi's pipeline
scenario](https://inbox.sourceware.org/cygwin-patches/20260923105326.d57b0710f1519e32b9c5d496@nifty.ne.jp/):
the Cygwin sleeper must be interrupted via Ctrl+C even when the native
side owns console input. The original DLL already passed this test, so
it protects against regressions in this existing behavior.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MSYS2 bash.exe wont quit

2 participants