Skip to content

Cygwin: console: backport mode handling v17 and owner-exit v3 (experimental) - #366

Closed
dscho wants to merge 5 commits into
msys2:msys2-3.6.10from
dscho:try-console-mode-v17
Closed

dscho wants to merge 5 commits into
msys2:msys2-3.6.10from
dscho:try-console-mode-v17

Conversation

@dscho

@dscho dscho commented Sep 17, 2026 •

Copy link
Copy Markdown
Collaborator

This is expected to be the final version of these two patches (plus prerequisite), or at least quite close to their final form.

(This AI-generated PR description still needs to be edited by @dscho)

This new draft tests the current upstream proposals against #351. #364 stays at v15 plus fixup dbc070a9.

try-console-mode-v17 is based on msys2-3.6.10 (da84778cbc92), with this stack in order:

  1. Reused prerequisite c892dfe93ec1f5a82d299efca8c0297ff7ade794, backport of upstream bbd3710fc83451426e3a58e5032437ca535fa444.
  2. Console mode handling v17, 2b85c1d1c1fd.
  3. Takashi's companion owner-exit v3, ea9117799e5c (tested HEAD).

The committed trees were independently verified against the submissions. V17 required only the existing release-context/preimage adaptations; every added line is preserved, and owner-exit v3 was applied verbatim. No separate local fixup or instrumentation was added.

The local DLL-only build of new-msys-2.0.dll succeeded with the MSYS toolchain and tested HEAD embedded. The loaded runtime's path and hash were verified.

Testing used the same #351 reproducer binary as the baseline/v15/v16 comparisons, based on 4a0117da with existing child-command failure checks. Workload settings remained 99 jobs, concurrency 10, and unchanged delays. Five consecutive uninstrumented runs passed (495 jobs total): all IDs 1-99 and END OF MAIN observed in every run, normal exit status 0, no child-command failures, and no monitor errors.

Upstream review is ongoing. Local validation did not include the full utility/install/MSYS2 CI matrix or a new compiler bootstrap. These results cover the #351 workload, not every console race or a general resolution of MSYS2-packages#6445.

tyan0 and others added 5 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 v17 to the msys2-3.6.10 release branch after prerequisite
c892dfe, preserving all additions from
https://inbox.sourceware.org/cygwin-patches/20260917054034.7668-1-takashi.yano@nifty.ne.jp/

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 owner-v3 unchanged on top of v17 to the msys2-3.6.10 release
branch, including the owner-liveness handling suggested in Johannes's review:
https://inbox.sourceware.org/cygwin-patches/20260917054209.7682-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>
…in apps

Signal exits, SA_RESTART retries and noncanonical reads needing more input
can bypass deferred Win32 input-mode reconciliation. Apply pending
changes before console reads and readiness checks retry or return.

Invoke reconciliation only after releasing input_mutex to preserve the
cons_mode_mutex-before-input_mutex lock order.

Assisted-by: GPT-6
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
…on.owner

An owner query failure does not necessarily mean the process exited, and
observing exit is not a worker acknowledgement.

Allow an owner-exit escape only on observed exit or absence, with
con.owner still matching the captured owner. Leave the acknowledgement
untouched and preserve -1 as normal retirement. Log inconclusive query
or wait failures once per newly observed failing owner and keep waiting.

Assisted-by: GPT-6
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
@dscho

dscho commented Sep 24, 2026 •

Copy link
Copy Markdown
Collaborator Author

Superseded by #368

@dscho dscho closed this Sep 24, 2026
@dscho
dscho deleted the try-console-mode-v17 branch September 24, 2026 10:54
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.

2 participants