fix(config): stop config create spinning forever on closed stdin - #179
Merged
Conversation
tas50
force-pushed
the
fix/config-create-eof-hang
branch
from
September 8, 2026 15:15
698e1aa to
827d212
Compare
`promptNoDefault` swallowed io.EOF and returned an empty string, so the "New profile name" loop in `promptExistingFileAction` rejected the empty answer and asked again, forever. Running `cinc config create < /dev/null` against a credentials file that already had profiles pinned a core and flooded stdout: a probe measured 57 million prompts in 20 seconds. The action prompt defaults to "Add a new profile", so nothing unusual is needed to reach it: any non-interactive invocation with an existing credentials file hangs. `promptNoDefault` now separates the two cases a bare `""` used to conflate. An empty line is still a real answer (the collision and replace prompts treat Enter as their default), but a reader with nothing left to give returns errStdinExhausted, which names the flags that configure a profile without prompting. `promptWithDefault` is deliberately unchanged: falling back to the default on EOF is what lets the onboarding flow accept defaults, and it cannot loop. Signed-off-by: Tim Smith <tim@mondoo.com>
tas50
force-pushed
the
fix/config-create-eof-hang
branch
from
September 8, 2026 17:32
827d212 to
16e0125
Compare
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.
The defect
promptNoDefaultswallowsio.EOFand returns"". The "New profile name" loop inpromptExistingFileActionrejects an empty name andcontinues, so with nothing left on stdin it asks again forever.A probe measured 57,593,758 prompts in 20 seconds, at 100% CPU, flooding stdout. Nothing exotic is needed to reach it: the action prompt defaults to "Add a new profile", so any non-interactive invocation against a credentials file that already holds profiles hangs. That includes CI jobs and anything piping input.
promptProfilePickersurvives the same treatment only by accident, because its empty answer happens to map onto the default"1".The fix
Separate the two cases a bare
""was conflating:Update it instead? [Y/n]) and the replace prompt (Replace the file? [y/N]) both treat Enter as their default, and that still works.errStdinExhausted, which names the flags that configure a profile without prompting.promptWithDefaultis deliberately left alone. Returning the default on EOF is exactly what lets the onboarding flow accept defaults, and it has no loop to spin in.Tests
TestConfigureStopsWhenStdinIsExhausteddrives the real command with a closed stdin behind a 10s timeout. It fails onmainby never returning (reporting the prompt count) and passes here.go test ./...,go vet ./..., andgofmt -l .are all clean.