Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

Merged
merged 2 commits into from
Sep 22, 2023
Merged

Conversation

thrau
Copy link
Member

@thrau thrau commented Sep 22, 2023

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.

Peek 2023-09-22 18-03

It looks like the tty=True option of run doesn't really work correctly. For #8994 I added a run_interactive method that is a much simpler implementation of running an interactive command in a subprocess. Using os.execlp (based on @dfangl's suggestion), is much simpler. This works much better now:

Peek 2023-09-22 18-03-update

Changes

  • Use run_interactive for localstack ssh

@thrau thrau requested a review from alexrashed as a code owner September 22, 2023 16:08
@thrau thrau requested a review from dfangl September 22, 2023 16:09
@coveralls
Copy link

coveralls commented Sep 22, 2023

Coverage Status

coverage: 82.952% (+0.01%) from 82.94% when pulling 9713bfe on fix-cli-ssh into 4d3a8b1 on master.

@thrau thrau added the semver: minor Non-breaking changes which can be included in minor releases, but not in patch releases label Sep 22, 2023
@github-actions
Copy link

github-actions bot commented Sep 22, 2023

LocalStack Community integration with Pro

       2 files         2 suites   1h 15m 56s ⏱️
2 217 tests 1 721 ✔️ 496 💤 0
2 218 runs  1 721 ✔️ 497 💤 0

Results for commit 9713bfe.

♻️ This comment has been updated with latest results.


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"])
Copy link
Member

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.

Copy link
Member Author

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 👍

Copy link
Member

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 :)

Copy link
Member

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 :)

@thrau thrau merged commit 8536a1c into master Sep 22, 2023
@thrau thrau deleted the fix-cli-ssh branch September 22, 2023 22:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver: minor Non-breaking changes which can be included in minor releases, but not in patch releases
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants