bitprophet/ssh — pull request #26 by lynxis (2012-05-06 12:36:58+00:00)
Title: fix a racecondition within ssh-agent-forwarding code.

As long you use ssh-agent-forwarding more than once within a connection you get into a racecondition.
Multiple select's waiting for new data on your local ssh-agent socket. sshd will create a new channel for each connect to the fake-agent-socket on the remote server. On the py-ssh side all incoming ssh-agent packets going over _ONE_ connection to the agent. E.g. open a py-ssh connection with agent-forwarding to a remote server. execute multiple times 'ssh-add -l' sometimes it will hang, because py-ssh received from channel 1 a ssh-auth-packet, forward it to local ssh-agent and channel 2's select see new data arrived and send it back over channel 2 instead of channel 1.
You can test it with fabric and ssh

run "fab -H host sleep"
while fabric sleeps connect with ssh and set env "export SSH_AUTH_SOCK=/tmp/ssh-XXXXXX/agent." ; ssh-add -l ; ssh-add -l

from fabric.api import run, task, env
env.forward_agent = True
@task
def sleep():
run("sleep 360")