Log in

No account? Create an account


An OpenSSH patch

« previous entry | next entry »
3rd Aug 2007 | 20:13

OpenSSH has a neat feature called ControlMaster which allows multiple ssh clients to share the same connection to a target host. This saves time on connection startup by eliminating all the cryptography and authentication for the second and subsequent clients. You can use the feature by explicitly telling ssh when to be a control master (supply -M and -S <socketpath> arguments) and when to be a control client (just supply a -S <socketpath> argument). However it's much more convenient to tell it to automatically be a master if there isn't already one, or a client if there is, by putting ControlMaster=auto in your .ssh/config file.

However there is a race in the setup of the communications socket in auto mode, as illustrated by the following command line:

ssh -oControlMaster=auto -oControlPath=sock localhost 'sleep 1; echo 1' &
ssh -oControlMaster=auto -oControlPath=sock localhost 'sleep 2; echo 2' &

Both of the commands will try to start up as a control client, find that sock does not exist, and switch into control master mode. One will succeed in creating the control master socket and the other will fail and bomb.

I've written a patch which eliminates this race by trying to create a control master socket first, and falling back to control client mode if master mode fails. See the attachment to the message I posted to the openssh-dev list.

| Leave a comment | Share

Comments {0}