Fix bugs causing hangs - #368
Merged
Merged
Conversation
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
marked this pull request as ready for review
September 24, 2026 12:06
This was referenced Sep 24, 2026
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
c892dfe93e: the complete prerequisite, including the companiondtable.ccstandard-handle change.92c1e00a38: console-mode v18, including reconciliation on signal and read-retry paths.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