[CLI Bug] CLI leaves terminal TTY state corrupted (echo disabled/raw mode) after SIGINT or detaching with -d #41
patrickryankenneth
started this conversation in
Bugs
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Description
When running the LocalStack CLI (
localstack startorlocalstack start -d) using Podman as the backend container engine, the CLI alters the host terminal's TTY line discipline (disabling keyboard echo and switching to raw mode).However, if the CLI process is interrupted via SIGINT (
Ctrl-C) during startup, or when it forks/detaches under the-dflag, the CLI fails to restore the TTY settings to standard/cooked mode before returning control to the shell. This leaves the active user shell completely broken (character echoing is disabled, line formatting is corrupted, and keyboard inputs fail to render), forcing users to manually runresetorstty saneto recover their shell.At minimum, detached mode (
-d) should run without depending on or mutating the caller's stdin/stdout TTY state, and any terminal mode changes made during startup must be reliably restored before returning control to the shell.Environment
DOCKER_HOST)Steps to Reproduce
Scenario A (Signal Interruption):
localstack startCtrl-C) during the startup or shutdown sequence.Scenario B (Detached Mode):
localstack start -ddetachingand return control to the shell.Expected Behavior
signal/atexitmodules or standardtry/finallyblocks) to ensure the standard terminal discipline is restored (stty saneequivalent) regardless of how the CLI exits.-d) is requested, the CLI should safely run in a non-interactive mode that does not attach to, mutate, or retain the parent shell's controlling TTY.Additional Findings & Diagnostic Workaround
The issue appears to be tied specifically to the LocalStack CLI interacting with the caller's controlling TTY during startup, even when
-d(detached) is supplied.Launching the exact same detached start path through a TTY-isolated wrapper completely avoids the corruption:
By forcing standard input to
/dev/nulland usingsetsidto strip the controlling terminal, Python'ssys.stdin.isatty()returnsFalse. This successfully prevents the CLI from attempting to alter the terminal line discipline, and the shell remains fully responsive.This strongly indicates that the CLI is unnecessarily attempting to hook into and mutate the parent TTY during detached startup, without wrapping those mutations in a safe restoration routine.
Beta Was this translation helpful? Give feedback.
All reactions