Skip to content

stdin: fix watcher mode swallowing first message after reload#392

Merged
mmatczuk merged 3 commits intomainfrom
connect-1733
Mar 19, 2026
Merged

stdin: fix watcher mode swallowing first message after reload#392
mmatczuk merged 3 commits intomainfrom
connect-1733

Conversation

@twmb
Copy link
Copy Markdown
Contributor

@twmb twmb commented Mar 16, 2026

When watcher mode reloads config, the old stdin consumer's bufio.Scanner blocks in os.Stdin.Read and cannot be cancelled. A new consumer starts a second Read on the same fd, and whichever goroutine wins the race consumes the data — if the old one wins, the message is silently dropped.

Replace io.NopCloser(os.Stdin) with a singleton relay goroutine that owns the only Read on os.Stdin and fans data through a channel. Each consumer gets a cancelableStdinReader whose Read selects on the relay channel, the caller's context, and a close signal. On context cancellation the old reader returns immediately, unblocking the scanner so the goroutine can exit, and the next consumer picks up seamlessly from the same relay.

Closes redpanda-data/connect#1733

twmb and others added 3 commits March 16, 2026 16:39
When watcher mode reloads config, the old stdin consumer's
bufio.Scanner blocks in os.Stdin.Read and cannot be cancelled. A new
consumer starts a second Read on the same fd, and whichever goroutine
wins the race consumes the data — if the old one wins, the message is
silently dropped.

Replace io.NopCloser(os.Stdin) with a singleton relay goroutine that
owns the only Read on os.Stdin and fans data through a channel. Each
consumer gets a cancelableStdinReader whose Read selects on the relay
channel, the caller's context, and a close signal. On context
cancellation the old reader returns immediately, unblocking the scanner
so the goroutine can exit, and the next consumer picks up seamlessly
from the same relay.

Closes redpanda-data/connect#1733

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@claude
Copy link
Copy Markdown

claude bot commented Mar 19, 2026

Commits
LGTM

Review
Introduces a singleton stdinRelay goroutine that owns the only Read on os.Stdin and fans data through a channel, paired with a cancelableStdinReader that respects context cancellation and close signals. This cleanly fixes the race where old and new consumers competed for stdin data during watcher-mode reloads. Tests cover cancellation, close idempotency, buffering, relay errors, and the reload handoff scenario.

LGTM

@mmatczuk mmatczuk self-requested a review March 19, 2026 13:02
Copy link
Copy Markdown
Contributor

@mmatczuk mmatczuk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM low risk

@mmatczuk mmatczuk merged commit 298d708 into main Mar 19, 2026
4 checks passed
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.

Watcher mode with stdin/stdout swallows first message after reload

2 participants