-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
use run_interactive for localstack ssh to fix tty issues #9211
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
localstack/cli/localstack.py
Outdated
|
||
if not DOCKER_CLIENT.is_container_running(config.MAIN_CONTAINER_NAME): | ||
raise CLIError( | ||
f'Expected a running LocalStack container named "{config.MAIN_CONTAINER_NAME}", but found none' | ||
) | ||
try: | ||
process = run("docker exec -it %s bash" % config.MAIN_CONTAINER_NAME, tty=True) | ||
process.wait() | ||
run_interactive(["docker", "exec", "-it", config.MAIN_CONTAINER_NAME, "bash"]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would argue that we do not need run_interactive here. It would only be necessary when we want to do something afterwards.
In this case, I would suggest using os.execv*
here, as replacing the current process with the new one makes sure every signal is handled as intended.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fair point. i don't really understand os.exec
well and how it works on other platforms, but works fine on my machine this way 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It replaces the current process image with a new process image. Instead of running two processes, we only run one, and all signals will therefore get directly to docker, without any logic on our side :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be available on unix and windows :)
Motivation
While working on #9210, I noticed that
localstack ssh
had some wonky terminal behavior.I couldn't use CTRL+A, CTRL+E, CTRL+R and other control sequences correctly. New lines were also added twice.
It looks like the
tty=True
option ofrun
doesn't really work correctly.For #8994 I added aUsingrun_interactive
method that is a much simpler implementation of running an interactive command in a subprocess.os.execlp
(based on @dfangl's suggestion), is much simpler. This works much better now:Changes
run_interactive
forlocalstack ssh