Skip to content

fix: return terminal control to parent on quit#142

Open
youdie006 wants to merge 1 commit into
control-theory:mainfrom
youdie006:fix/clean-exit-on-quit
Open

fix: return terminal control to parent on quit#142
youdie006 wants to merge 1 commit into
control-theory:mainfrom
youdie006:fix/clean-exit-on-quit

Conversation

@youdie006

Copy link
Copy Markdown

Summary

In stdin mode (e.g. kubectl logs -f ... | gonzo, the K9s plugin), pressing q cancelled the app context but left an inner goroutine blocked on a read of os.Stdin. On a live pipe that read never sees EOF, so it keeps holding the TTY/pipe fd and the parent (K9s) only regains control after a follow-up Ctrl-C — the black-screen-until-keypress behavior in #58.

Fix

On quit, close the stdin reader (guarded by sync.Once) so the blocked read returns immediately and the goroutine exits, returning control to the parent without Ctrl-C. Also return on EOF (the old code re-spawned the scan and busy-spun). Adds a unit test for the teardown seam (a blocking reader that unblocks on Close).

(Incidental: the touched file picked up a gofmt import reorder.)

Closes #58

In stdin mode (e.g. kubectl logs -f ... | gonzo), readStdinAsync's inner
goroutine blocks on a read of os.Stdin that never sees EOF on a live pipe, so
on 'q' the context is cancelled but the blocked read keeps holding the TTY/pipe
fd and the parent (K9s) only regains control after a follow-up Ctrl-C. Close the
stdin reader on quit (sync.Once) so the blocked read returns immediately and the
goroutine exits, and return on EOF to fix a busy-spin. Adds a teardown test.
(Incidental: gofmt import reorder in the touched file.)

Closes control-theory#58
@destari

destari commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Hey! thanks for the PR!
It looks good at quick glance, but I will test it and approve this weekend

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.

Need to hit "Ctrl-c" after hitting "q" when exiting Gonzo back to K9s when using K9s plugin

2 participants