yori icon indicating copy to clipboard operation
yori copied to clipboard

control-c causes yori prompt to come back while background interactive session still running

Open mattgillard opened this issue 5 years ago • 1 comments

My scenario is using the aws cli and session manager to login to a remote host. I use: >aws ssm start-session --target i- Everything works fine until i hit control-c - then the yori prompt comes back interleaved with my remote session even though my aws session is still active:

ssm-user@ip-10-0-3-189:/var/snap/amazon-ssm-agent/1565$ C:\Users\matt\OneDrive\Documents\dev> ssm-user@ip-10-0-3-189:/var/snap/amazon-ssm-agent/1565$ C:\Users\matt\OneDrive\Documents\dev>

Situation is unusable until i go into a second session and kill my first one with aws ssm terminate-session. Then i can re-connect fine. Its like yori took control of my control-c and thought i wanted to terminate the aws ssm process but it doesnt realise it is an interactive session?

Using ssh is fine - control-c works as expected. aws ssm start-session works as expected in a cmd.exe session.

thanks!

mattgillard avatar Apr 22 '20 23:04 mattgillard

I looked into this a bit, but it looks like the aws cli went out of its way to make this happen. See:

https://github.com/aws/aws-cli/blob/e87b769bd717b895e00fd48a3b5592db825402ef/awscli/compat.py#L332

This is used when creating sessions specifically to prevent the child from receiving the Ctrl+C signal. Yori, and CMD, both launch child processes in a mode where the Ctrl+C is sent to those processes and they terminate themselves. The aws cli is suppressing receipt of the message.

One difference between Yori and CMD is that Yori will wait 50ms for the child process to die, and if it doesn't it is killed forcibly with TerminateProcess. That means if Yori launches one process, and that process launches another process, it is willing to kill the immediate child and leave its child running, which is probably what happened here. My knee-jerk reaction to this is to use job objects to kill all processes - but note that doing so is doing the exact opposite of what the aws cli is trying to achieve.

malxau avatar Apr 25 '20 06:04 malxau