Skip to content

[data] Avoid stdin flood for non-TTY#289

Merged
ldmonster merged 1 commit intomainfrom
fix/data-ask-yesno-stdin-flood
Mar 3, 2026
Merged

[data] Avoid stdin flood for non-TTY#289
ldmonster merged 1 commit intomainfrom
fix/data-ask-yesno-stdin-flood

Conversation

@kkozoriz
Copy link
Contributor

@kkozoriz kkozoriz commented Feb 27, 2026

Description

Problem

In non-interactive environments (for example inside a pod, CI job, or any run without a TTY), AskYesNoWithTimeout could repeatedly print input error messages and create noisy output instead of gracefully falling back to a default decision.

Root cause

The confirmation loop kept retrying after read failures from stdin. In non-TTY scenarios this error is persistent, so the loop never recovered and continuously retried.
Additionally, the previous channel usage could lead to fragile behavior around timeout vs. input delivery.

Solution

  • Detect non-interactive mode early and return a safe default without prompting.
  • Use a buffered channel for one-shot answer delivery from the input goroutine.
  • On stdin read error, stop retrying, choose a default answer, and exit the goroutine.
  • Keep retries only for invalid user input (y/n validation).
  • Add short inline comments to document the non-TTY and error-handling behavior.

Syscalls / TTY detection

AskYesNoWithTimeout uses golang.org/x/term.IsTerminal to detect whether the session is interactive.
This is the recommended cross-platform approach: it relies on OS-specific implementations under the hood (ioctl on Unix-like systems and GetConsoleMode on Windows via build tags).
No custom direct syscall logic was added in this change, so platform portability and builds remain safe.

Before fix

2026-02-27.12.27.10.mov

After fix

image

Signed-off-by: Konstantin Kozoriz <konstantin.kozoriz@flant.com>
@kkozoriz kkozoriz requested a review from ldmonster as a code owner February 27, 2026 11:01
@kkozoriz kkozoriz self-assigned this Feb 27, 2026
@kkozoriz kkozoriz requested a review from ipaqsa March 2, 2026 17:52
@kkozoriz kkozoriz removed the request for review from AleksZimin March 3, 2026 08:37
@ldmonster ldmonster merged commit 21d8671 into main Mar 3, 2026
9 checks passed
@ldmonster ldmonster deleted the fix/data-ask-yesno-stdin-flood branch March 3, 2026 17:09
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.

4 participants