Skip to content

Instantly share code, notes, and snippets.

@hoytech
Created February 3, 2016 18:58
Show Gist options
  • Save hoytech/d3e19c6e860e224cbdd7 to your computer and use it in GitHub Desktop.
Save hoytech/d3e19c6e860e224cbdd7 to your computer and use it in GitHub Desktop.
Race condition with ssh -tt
ssh -o ServerAliveInterval=30 -o ControlPersist=no -2MNx -S .junk_socket localhost &
MAINPID=$!
sleep 1
ssh -tt -S .junk_socket localhost -- id &
PID1=$!
sleep 1 # <-- comment out this sleep to trigger race condition
ssh -tt -S .junk_socket localhost -- id &
PID2=$!
wait $PID1 $PID2
kill $MAINPID
@hoytech
Copy link
Author

hoytech commented Feb 3, 2016

With Net::OpenSSH I'm passing in {tty => 1} to make_remote_command so that I can use sudo. I am seeing spurious (?) warnings like process_mux_new_session: tcgetattr: Inappropriate ioctl for device as the Net::OpenSSH docs suggest I will.

However, I've noticed if I run 2 commands in parallel, I often hit a race condition where the control master dies unexpectedly. This gist is a simple shell script for reproducing this bug.

The script works reliably as is, but if you uncomment the sleep 1 command in the middle then about 50% of the time on my box both of the ssh localhost id commands error out with broken pipes (ssh -vvv says the master dies unexpectedly).

Throwing -vvv on the master ssh command line I see:

debug2: channel 3: request pty-req confirm 1
...
debug2: channel 4: request pty-req confirm 1
...
debug2: PTY allocation request accepted on channel 3

(2 requests but only one accept -- let me know if the entire output would be useful).

For now I'm trying to ensure that only 1 sudo request is running at once although this is a little bit sub-optimal.

@hoytech
Copy link
Author

hoytech commented Feb 3, 2016

As I mentioned in this Net::OpenSSH ticket:

salva/p5-Net-OpenSSH#19

I have given up on using -tt (tty => 1) and am making sure that sudo can function without a terminal by editing the /etc/sudoers file, see this bug:

https://bugzilla.redhat.com/show_bug.cgi?id=1020147

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment