Skip to content

Strange problem with paramiko + eventlet #173

Closed

Description

@foxx

Something to do with packet corruption..

Any ideas?

Cal

Exception

[2013-05-31 13:33:13,218] [transport.py:1404] [22522/dispatch0] starting thread (client mode): 0x295d750L
[2013-05-31 13:33:13,223] [transport.py:1404] [22522/dispatch0] Connected (version 2.0, client OpenSSH_5.5p1)
[2013-05-31 13:33:13,322] [transport.py:1404] [22522/dispatch0] kex algos:['diffie-hellman-group-exchange-sha256', 'diffie-hellman-group-exchange-sha1', 'diffie-hellman-group14-sha1', 'diffie-hellman-group1-sha1'] server key:['ssh-rsa', 'ssh-dss'] client encrypt:['aes128-ctr', 'aes192-ctr', 'aes256-ctr', 'arcfour256', 'arcfour128', 'aes128-cbc', '3des-cbc', 'blowfish-cbc', 'cast128-cbc', 'aes192-cbc', 'aes256-cbc', 'arcfour', '[email protected]'] server encrypt:['aes128-ctr', 'aes192-ctr', 'aes256-ctr', 'arcfour256', 'arcfour128', 'aes128-cbc', '3des-cbc', 'blowfish-cbc', 'cast128-cbc', 'aes192-cbc', 'aes256-cbc', 'arcfour', '[email protected]'] client mac:['hmac-md5', 'hmac-sha1', '[email protected]', 'hmac-ripemd160', '[email protected]', 'hmac-sha1-96', 'hmac-md5-96'] server mac:['hmac-md5', 'hmac-sha1', '[email protected]', 'hmac-ripemd160', '[email protected]', 'hmac-sha1-96', 'hmac-md5-96'] client compress:['none', '[email protected]'] server compress:['none', '[email protected]'] client lang:[''] server lang:[''] kex follows?False
[2013-05-31 13:33:13,322] [transport.py:1404] [22522/dispatch0] Ciphers agreed: local=aes128-ctr, remote=aes128-ctr
[2013-05-31 13:33:13,322] [transport.py:1404] [22522/dispatch0] using kex diffie-hellman-group1-sha1; server key type ssh-rsa; cipher: local aes128-ctr, remote aes128-ctr; mac: local hmac-sha1, remote hmac-sha1; compression: local none, remote none
[2013-05-31 13:33:13,418] [transport.py:1404] [22522/dispatch0] Switch to new keys ...
[2013-05-31 13:33:13,419] [transport.py:1404] [22522/dispatch0] Attempting public-key auth...
[2013-05-31 13:33:13,569] [transport.py:1404] [22522/dispatch0] userauth is OK
[2013-05-31 13:33:13,908] [transport.py:1404] [22522/dispatch0] Authentication (publickey) successful!
[2013-05-31 13:33:13,933] [channel.py:1108] [22522/dispatch0] [chan 1] Max packet in: 34816 bytes
[2013-05-31 13:33:13,959] [channel.py:1108] [22522/dispatch0] [chan 1] Max packet out: 32768 bytes
[2013-05-31 13:33:13,959] [transport.py:1404] [22522/dispatch0] Secsh channel 1 opened.
[2013-05-31 13:33:13,992] [channel.py:1108] [22522/dispatch0] [chan 1] Sesch channel 1 request ok
[2013-05-31 13:33:14,014] [sftp.py:132] [22522/dispatch0] [chan 1] Opened sftp connection (server version 3)
[2013-05-31 13:33:14,015] [sftp.py:132] [22522/dispatch0] [chan 1] open('/tmp/lol', 'wb')
[2013-05-31 13:33:14,056] [sftp.py:132] [22522/dispatch0] [chan 1] open('/tmp/lol', 'wb') -> 00000000
[2013-05-31 13:33:15,253] [transport.py:1404] [22522/dispatch0] Disconnect (code 2): Packet corrupt
[2013-05-31 13:33:15,298] [sftp.py:132] [22522/dispatch0] [chan 1] close(00000000)
[2013-05-31 13:33:16,090] [rockspawn.py:206] [22522/dispatch0] Traceback (most recent call last):

  File "/home/foxx/code/pippa/webapp/libs/rockspawn/rockspawn.py", line 198, in run
    cls_setup_t.wait()

  File "/usr/local/lib/python2.6/dist-packages/eventlet-0.12.1-py2.6.egg/eventlet/greenthread.py", line 168, in wait
    return self._exit_event.wait()

  File "/usr/local/lib/python2.6/dist-packages/eventlet-0.12.1-py2.6.egg/eventlet/event.py", line 120, in wait
    current.throw(*self._exc)

  File "/usr/local/lib/python2.6/dist-packages/eventlet-0.12.1-py2.6.egg/eventlet/greenthread.py", line 194, in main
    result = function(*args, **kwargs)

  File "adapters.py", line 290, in on_start
    tpool.execute(self.upload_file, "/tmp/lol", "/tmp/lol")

  File "/usr/local/lib/python2.6/dist-packages/eventlet-0.12.1-py2.6.egg/eventlet/tpool.py", line 76, in tworker
    rv = meth(*args,**kwargs)

  File "adapters.py", line 258, in upload_file
    print sftp.put(local_path, remote_path)

  File "/usr/local/lib/python2.6/dist-packages/paramiko-1.10.1-py2.6.egg/paramiko/sftp_client.py", line 615, in put
    return self.putfo(fl, remotepath, os.stat(localpath).st_size, callback, confirm)

  File "/usr/local/lib/python2.6/dist-packages/paramiko-1.10.1-py2.6.egg/paramiko/sftp_client.py", line 570, in putfo
    fr.write(data)

  File "/usr/local/lib/python2.6/dist-packages/paramiko-1.10.1-py2.6.egg/paramiko/file.py", line 314, in write
    self._write_all(data)

  File "/usr/local/lib/python2.6/dist-packages/paramiko-1.10.1-py2.6.egg/paramiko/file.py", line 439, in _write_all
    count = self._write(data)

  File "/usr/local/lib/python2.6/dist-packages/paramiko-1.10.1-py2.6.egg/paramiko/sftp_file.py", line 168, in _write
    self._reqs.append(self.sftp._async_request(type(None), CMD_WRITE, self.handle, long(self._realpos), str(data[:chunk])))

  File "/usr/local/lib/python2.6/dist-packages/paramiko-1.10.1-py2.6.egg/paramiko/sftp_client.py", line 710, in _async_request
    self._send_packet(t, str(msg))

  File "/usr/local/lib/python2.6/dist-packages/paramiko-1.10.1-py2.6.egg/paramiko/sftp.py", line 172, in _send_packet
    self._write_all(out)

  File "/usr/local/lib/python2.6/dist-packages/paramiko-1.10.1-py2.6.egg/paramiko/sftp.py", line 136, in _write_all
    n = self.sock.send(out)

  File "/usr/local/lib/python2.6/dist-packages/paramiko-1.10.1-py2.6.egg/paramiko/channel.py", line 734, in send
    self.transport._send_user_message(m)

  File "/usr/local/lib/python2.6/dist-packages/paramiko-1.10.1-py2.6.egg/paramiko/transport.py", line 1444, in _send_user_message
    self._send_message(data)

  File "/usr/local/lib/python2.6/dist-packages/paramiko-1.10.1-py2.6.egg/paramiko/transport.py", line 1424, in _send_message
    self.packetizer.send_message(data)

  File "/usr/local/lib/python2.6/dist-packages/paramiko-1.10.1-py2.6.egg/paramiko/packet.py", line 319, in send_message
    self.write_all(out)

  File "/usr/local/lib/python2.6/dist-packages/paramiko-1.10.1-py2.6.egg/paramiko/packet.py", line 269, in write_all
    raise EOFError()

EOFError

[2013-05-31 13:33:16,090] [rockspawn.py:207] [22522/dispatch0] watchdog failure: uncaught process exception
[2013-05-31 13:33:16,090] [rockspawn.py:406] [22522/dispatch0] Process stopped
[2013-05-31 13:33:16,102] [rockspawn.py:692] [22503/MainProcess] watchdog: detected dead instance: dispatch0
[2013-05-31 13:33:16,102] [rockspawn.py:511] [22503/MainProcess] Stopping

Code

    def upload_file(self, local_path, remote_path, verify=False):
        pkey = paramiko.RSAKey.from_private_key_file(self.private_key_path)

        t = paramiko.Transport((self.storage.ssh_host, 22))
        t.connect(username=self.storage.ssh_user, pkey=pkey)
        sftp = paramiko.SFTPClient.from_transport(t)
        print sftp.put(local_path, remote_path)
        return

Server side:

May 31 08:34:57 web1 sshd[15152]: Accepted publickey for pippaprod from 1.2.3.4 port 52456 ssh2
May 31 08:34:57 web1 sshd[15152]: pam_unix(sshd:session): session opened for user pippaprod by (uid=0)
May 31 08:34:57 web1 sshd[15155]: subsystem request for sftp
May 31 08:34:58 web1 sshd[15155]: Corrupted MAC on input.
May 31 08:34:58 web1 sshd[15155]: Disconnecting: Packet corrupt
May 31 08:34:58 web1 sshd[15152]: pam_unix(sshd:session): session closed for user pippaprod

Activity

  1. foxx commented on May 31, 2013

    @foxx
    Author

    If I remove eventlet from the equasion, the problem goes away;

    pkey = paramiko.RSAKey.from_private_key_file(fpath)
    t = paramiko.Transport((host, 22))
    t.connect(username=user, pkey=pkey)
    sftp = paramiko.SFTPClient.from_transport(t)
    print sftp.put("/tmp/lol", "/tmp/lol")
    

    I'm guessing that paramiko is not compatible with eventlet, but I'm surprised it is breaking so hard.

    Cal

  2. foxx commented on May 31, 2013

    @foxx
    Author

    Added some debug into eventlet, the send fails due to the socket being closed;

    [2013-05-31 16:33:57,581] [transport.py:1404] [28410/dispatch0] Disconnect (code 2): Packet corrupt
    Traceback (most recent call last):
      File "/usr/local/lib/python2.6/dist-packages/eventlet-0.12.1-py2.6.egg/eventlet/greenio.py", line 280, in send
        total_sent += fd.send(data[total_sent:], flags)
      File "/usr/lib/python2.6/socket.py", line 167, in _dummy
        raise error(EBADF, 'Bad file descriptor')
    error: [Errno 9] Bad file descriptor
    

    So it seems that the server is hard dropping the connection, which in turn raises an EOFError(). I'm going to look into the sending structure and see if eventlet is somehow causing some packet misordering or something

  3. foxx commented on May 31, 2013

    @foxx
    Author

    Bit more information, it seems to happen quite randomly. I can do a transfer in one test of 300KB and it will work fine, but on the next test it will fail. If I increase the file size to 1000KB, it always fails.

    I've tested with CLI scp/rsync and I do not get this same problem. I am also able to run both tests outside of eventlet with no errors.

    I tried with the lowest hub possible (selects) and this did not make any difference. I tried disabling 'thread' monkey_patch, this did not make any difference.

    I made eventlet print the datalen on every send() call, which resulted in;

    [2013-05-31 17:08:27,145] [greenio.py:280] [29769/dispatch0] 144
    [2013-05-31 17:08:27,243] [greenio.py:280] [29769/dispatch0] 16
    [2013-05-31 17:08:27,244] [transport.py:1404] [29769/dispatch0] Switch to new keys ...
    [2013-05-31 17:08:27,277] [transport.py:1404] [29769/dispatch0] Attempting public-key auth...
    [2013-05-31 17:08:27,277] [greenio.py:280] [29769/dispatch0] 52
    [2013-05-31 17:08:27,351] [transport.py:1404] [29769/dispatch0] userauth is OK
    [2013-05-31 17:08:27,650] [greenio.py:280] [29769/dispatch0] 644
    [2013-05-31 17:08:27,673] [transport.py:1404] [29769/dispatch0] Authentication (publickey) successful!
    [2013-05-31 17:08:27,684] [channel.py:1108] [29769/dispatch0] [chan 1] Max packet in: 34816 bytes
    [2013-05-31 17:08:27,684] [greenio.py:280] [29769/dispatch0] 68
    [2013-05-31 17:08:27,716] [channel.py:1108] [29769/dispatch0] [chan 1] Max packet out: 32768 bytes
    [2013-05-31 17:08:27,716] [transport.py:1404] [29769/dispatch0] Secsh channel 1 opened.
    [2013-05-31 17:08:27,720] [greenio.py:280] [29769/dispatch0] 68
    [2013-05-31 17:08:27,777] [channel.py:1108] [29769/dispatch0] [chan 1] Sesch channel 1 request ok
    [2013-05-31 17:08:27,778] [greenio.py:280] [29769/dispatch0] 52
    [2013-05-31 17:08:27,814] [sftp.py:132] [29769/dispatch0] [chan 1] Opened sftp connection (server version 3)
    [2013-05-31 17:08:27,814] [sftp.py:132] [29769/dispatch0] [chan 1] open('/tmp/lol', 'wb')
    [2013-05-31 17:08:27,814] [greenio.py:280] [29769/dispatch0] 68
    [2013-05-31 17:08:27,858] [sftp.py:132] [29769/dispatch0] [chan 1] open('/tmp/lol', 'wb') -> 00000000
    [2013-05-31 17:08:27,859] [greenio.py:280] [29769/dispatch0] 32756
    [2013-05-31 17:08:27,859] [greenio.py:280] [29769/dispatch0] 132
    [2013-05-31 17:08:27,860] [greenio.py:280] [29769/dispatch0] 32756
    [2013-05-31 17:08:27,860] [greenio.py:280] [29769/dispatch0] 32756
    [2013-05-31 17:08:27,860] [greenio.py:280] [29769/dispatch0] 132
    [2013-05-31 17:08:27,861] [greenio.py:280] [29769/dispatch0] 32756
    [2013-05-31 17:08:27,861] [greenio.py:280] [29769/dispatch0] 32756
    [2013-05-31 17:08:27,862] [greenio.py:280] [29769/dispatch0] 132
    [2013-05-31 17:08:27,862] [greenio.py:280] [29769/dispatch0] 32756
    [2013-05-31 17:08:27,862] [greenio.py:280] [29769/dispatch0] 132
    [2013-05-31 17:08:27,863] [greenio.py:280] [29769/dispatch0] 32756
    [2013-05-31 17:08:27,863] [greenio.py:280] [29769/dispatch0] 132
    [2013-05-31 17:08:27,864] [greenio.py:280] [29769/dispatch0] 32756
    [2013-05-31 17:08:27,864] [greenio.py:280] [29769/dispatch0] 132
    [2013-05-31 17:08:27,865] [greenio.py:280] [29769/dispatch0] 32756
    [2013-05-31 17:08:27,966] [greenio.py:280] [29769/dispatch0] 32756
    [2013-05-31 17:08:28,067] [greenio.py:280] [29769/dispatch0] 32756
    [2013-05-31 17:08:28,168] [greenio.py:280] [29769/dispatch0] 32756
    [2013-05-31 17:08:28,269] [greenio.py:280] [29769/dispatch0] 32756
    [2013-05-31 17:08:28,370] [greenio.py:280] [29769/dispatch0] 32756
    [2013-05-31 17:08:28,428] [greenio.py:280] [29769/dispatch0] 32756
    [2013-05-31 17:08:28,429] [greenio.py:280] [29769/dispatch0] 132
    [2013-05-31 17:08:28,429] [greenio.py:280] [29769/dispatch0] 32756
    

    I tried both setblocking 0/1, inside transport.py, both with no effect;

    sock.setblocking(0) and sock.setblocking(1)
    

    So, I printed out the data packet sizes on each packet sent, for both a failed test and a good test;

    BAD TEST:

    [2013-05-31 17:17:34,216] [transport.py:1404] [30312/dispatch0] starting thread (client mode): 0x2957850L
    [2013-05-31 17:17:34,216] [greenio.py:280] [30312/dispatch0] 25
    [2013-05-31 17:17:34,217] [transport.py:1404] [30312/dispatch0] Connected (version 2.0, client OpenSSH_5.5p1)
    [2013-05-31 17:17:34,218] [greenio.py:280] [30312/dispatch0] 416
    [2013-05-31 17:17:34,232] [transport.py:1404] [30312/dispatch0] kex algos:['diffie-hellman-group-exchange-sha256', 'diffie-hellman-group-exchange-sha1', 'diffie-hellman-group14-sha1', 'diffie-hellman-group1-sha1'] server key:['ssh-rsa', 'ssh-dss'] client encrypt:['aes128-ctr', 'aes192-ctr', 'aes256-ctr', 'arcfour256', 'arcfour128', 'aes128-cbc', '3des-cbc', 'blowfish-cbc', 'cast128-cbc', 'aes192-cbc', 'aes256-cbc', 'arcfour', '[email protected]'] server encrypt:['aes128-ctr', 'aes192-ctr', 'aes256-ctr', 'arcfour256', 'arcfour128', 'aes128-cbc', '3des-cbc', 'blowfish-cbc', 'cast128-cbc', 'aes192-cbc', 'aes256-cbc', 'arcfour', '[email protected]'] client mac:['hmac-md5', 'hmac-sha1', '[email protected]', 'hmac-ripemd160', '[email protected]', 'hmac-sha1-96', 'hmac-md5-96'] server mac:['hmac-md5', 'hmac-sha1', '[email protected]', 'hmac-ripemd160', '[email protected]', 'hmac-sha1-96', 'hmac-md5-96'] client compress:['none', '[email protected]'] server compress:['none', '[email protected]'] client lang:[''] server lang:[''] kex follows?False
    [2013-05-31 17:17:34,232] [transport.py:1404] [30312/dispatch0] Ciphers agreed: local=aes128-ctr, remote=aes128-ctr
    [2013-05-31 17:17:34,232] [transport.py:1404] [30312/dispatch0] using kex diffie-hellman-group1-sha1; server key type ssh-rsa; cipher: local aes128-ctr, remote aes128-ctr; mac: local hmac-sha1, remote hmac-sha1; compression: local none, remote none
    [2013-05-31 17:17:34,250] [greenio.py:280] [30312/dispatch0] 144
    [2013-05-31 17:17:34,340] [greenio.py:280] [30312/dispatch0] 16
    [2013-05-31 17:17:34,340] [transport.py:1404] [30312/dispatch0] Switch to new keys ...
    [2013-05-31 17:17:34,341] [transport.py:1404] [30312/dispatch0] Attempting public-key auth...
    [2013-05-31 17:17:34,342] [greenio.py:280] [30312/dispatch0] 52
    [2013-05-31 17:17:34,429] [transport.py:1404] [30312/dispatch0] userauth is OK
    [2013-05-31 17:17:34,726] [greenio.py:280] [30312/dispatch0] 644
    [2013-05-31 17:17:34,776] [transport.py:1404] [30312/dispatch0] Authentication (publickey) successful!
    [2013-05-31 17:17:34,782] [channel.py:1108] [30312/dispatch0] [chan 1] Max packet in: 34816 bytes
    [2013-05-31 17:17:34,783] [greenio.py:280] [30312/dispatch0] 68
    [2013-05-31 17:17:34,805] [channel.py:1108] [30312/dispatch0] [chan 1] Max packet out: 32768 bytes
    [2013-05-31 17:17:34,805] [transport.py:1404] [30312/dispatch0] Secsh channel 1 opened.
    [2013-05-31 17:17:34,818] [greenio.py:280] [30312/dispatch0] 68
    [2013-05-31 17:17:34,846] [channel.py:1108] [30312/dispatch0] [chan 1] Sesch channel 1 request ok
    [2013-05-31 17:17:34,847] [greenio.py:280] [30312/dispatch0] 52
    [2013-05-31 17:17:34,868] [sftp.py:132] [30312/dispatch0] [chan 1] Opened sftp connection (server version 3)
    [2013-05-31 17:17:34,869] [sftp.py:132] [30312/dispatch0] [chan 1] open('/tmp/lol', 'wb')
    [2013-05-31 17:17:34,869] [greenio.py:280] [30312/dispatch0] 68
    [2013-05-31 17:17:34,911] [sftp.py:132] [30312/dispatch0] [chan 1] open('/tmp/lol', 'wb') -> 00000000
    [2013-05-31 17:17:34,913] [greenio.py:280] [30312/dispatch0] 32756
    [2013-05-31 17:17:34,914] [greenio.py:280] [30312/dispatch0] 132
    [2013-05-31 17:17:34,914] [greenio.py:280] [30312/dispatch0] 32756
    [2013-05-31 17:17:34,915] [greenio.py:280] [30312/dispatch0] 32756
    [2013-05-31 17:17:34,915] [greenio.py:280] [30312/dispatch0] 132
    [2013-05-31 17:17:34,916] [greenio.py:280] [30312/dispatch0] 32756
    [2013-05-31 17:17:34,916] [greenio.py:280] [30312/dispatch0] 132
    [2013-05-31 17:17:34,917] [greenio.py:280] [30312/dispatch0] 32756
    [2013-05-31 17:17:34,917] [greenio.py:280] [30312/dispatch0] 132
    [2013-05-31 17:17:34,918] [greenio.py:280] [30312/dispatch0] 32756
    [2013-05-31 17:17:34,918] [greenio.py:280] [30312/dispatch0] 132
    [2013-05-31 17:17:34,919] [greenio.py:280] [30312/dispatch0] 32756
    [2013-05-31 17:17:34,930] [greenio.py:280] [30312/dispatch0] 32756
    [2013-05-31 17:17:34,930] [greenio.py:280] [30312/dispatch0] 132
    [2013-05-31 17:17:34,930] [greenio.py:280] [30312/dispatch0] 32756
    [2013-05-31 17:17:34,931] [greenio.py:280] [30312/dispatch0] 132
    [2013-05-31 17:17:34,931] [greenio.py:280] [30312/dispatch0] 32756
    [2013-05-31 17:17:34,931] [greenio.py:280] [30312/dispatch0] 132
    [2013-05-31 17:17:34,932] [greenio.py:280] [30312/dispatch0] 32756
    [2013-05-31 17:17:35,033] [greenio.py:280] [30312/dispatch0] 32756
    [2013-05-31 17:17:35,134] [greenio.py:280] [30312/dispatch0] 32756
    [2013-05-31 17:17:35,235] [greenio.py:280] [30312/dispatch0] 32756
    [2013-05-31 17:17:35,336] [greenio.py:280] [30312/dispatch0] 32756
    [2013-05-31 17:17:35,336] [greenio.py:280] [30312/dispatch0] 132
    [2013-05-31 17:17:35,336] [greenio.py:280] [30312/dispatch0] 12356
    [2013-05-31 17:17:35,336] [sftp.py:132] [30312/dispatch0] [chan 1] close(00000000)
    [2013-05-31 17:17:35,337] [greenio.py:280] [30312/dispatch0] 68
    [2013-05-31 17:17:35,721] [transport.py:1404] [30312/dispatch0] Disconnect (code 2): Packet corrupt
    

    GOOD TEST:

    [2013-05-31 17:17:41,656] [transport.py:1404] [30353/dispatch0] starting thread (client mode): 0x2d2ee10L
    [2013-05-31 17:17:41,657] [greenio.py:280] [30353/dispatch0] 25
    [2013-05-31 17:17:41,657] [transport.py:1404] [30353/dispatch0] Connected (version 2.0, client OpenSSH_5.5p1)
    [2013-05-31 17:17:41,658] [greenio.py:280] [30353/dispatch0] 416
    [2013-05-31 17:17:41,672] [transport.py:1404] [30353/dispatch0] kex algos:['diffie-hellman-group-exchange-sha256', 'diffie-hellman-group-exchange-sha1', 'diffie-hellman-group14-sha1', 'diffie-hellman-group1-sha1'] server key:['ssh-rsa', 'ssh-dss'] client encrypt:['aes128-ctr', 'aes192-ctr', 'aes256-ctr', 'arcfour256', 'arcfour128', 'aes128-cbc', '3des-cbc', 'blowfish-cbc', 'cast128-cbc', 'aes192-cbc', 'aes256-cbc', 'arcfour', '[email protected]'] server encrypt:['aes128-ctr', 'aes192-ctr', 'aes256-ctr', 'arcfour256', 'arcfour128', 'aes128-cbc', '3des-cbc', 'blowfish-cbc', 'cast128-cbc', 'aes192-cbc', 'aes256-cbc', 'arcfour', '[email protected]'] client mac:['hmac-md5', 'hmac-sha1', '[email protected]', 'hmac-ripemd160', '[email protected]', 'hmac-sha1-96', 'hmac-md5-96'] server mac:['hmac-md5', 'hmac-sha1', '[email protected]', 'hmac-ripemd160', '[email protected]', 'hmac-sha1-96', 'hmac-md5-96'] client compress:['none', '[email protected]'] server compress:['none', '[email protected]'] client lang:[''] server lang:[''] kex follows?False
    [2013-05-31 17:17:41,672] [transport.py:1404] [30353/dispatch0] Ciphers agreed: local=aes128-ctr, remote=aes128-ctr
    [2013-05-31 17:17:41,673] [transport.py:1404] [30353/dispatch0] using kex diffie-hellman-group1-sha1; server key type ssh-rsa; cipher: local aes128-ctr, remote aes128-ctr; mac: local hmac-sha1, remote hmac-sha1; compression: local none, remote none
    [2013-05-31 17:17:41,691] [greenio.py:280] [30353/dispatch0] 144
    [2013-05-31 17:17:41,773] [greenio.py:280] [30353/dispatch0] 16
    [2013-05-31 17:17:41,773] [transport.py:1404] [30353/dispatch0] Switch to new keys ...
    [2013-05-31 17:17:41,775] [transport.py:1404] [30353/dispatch0] Attempting public-key auth...
    [2013-05-31 17:17:41,775] [greenio.py:280] [30353/dispatch0] 52
    [2013-05-31 17:17:41,860] [transport.py:1404] [30353/dispatch0] userauth is OK
    [2013-05-31 17:17:42,157] [greenio.py:280] [30353/dispatch0] 644
    [2013-05-31 17:17:42,179] [transport.py:1404] [30353/dispatch0] Authentication (publickey) successful!
    [2013-05-31 17:17:42,192] [channel.py:1108] [30353/dispatch0] [chan 1] Max packet in: 34816 bytes
    [2013-05-31 17:17:42,192] [greenio.py:280] [30353/dispatch0] 68
    [2013-05-31 17:17:42,257] [channel.py:1108] [30353/dispatch0] [chan 1] Max packet out: 32768 bytes
    [2013-05-31 17:17:42,257] [transport.py:1404] [30353/dispatch0] Secsh channel 1 opened.
    [2013-05-31 17:17:42,261] [greenio.py:280] [30353/dispatch0] 68
    [2013-05-31 17:17:42,276] [channel.py:1108] [30353/dispatch0] [chan 1] Sesch channel 1 request ok
    [2013-05-31 17:17:42,277] [greenio.py:280] [30353/dispatch0] 52
    [2013-05-31 17:17:42,291] [sftp.py:132] [30353/dispatch0] [chan 1] Opened sftp connection (server version 3)
    [2013-05-31 17:17:42,291] [sftp.py:132] [30353/dispatch0] [chan 1] open('/tmp/lol', 'wb')
    [2013-05-31 17:17:42,291] [greenio.py:280] [30353/dispatch0] 68
    [2013-05-31 17:17:42,307] [sftp.py:132] [30353/dispatch0] [chan 1] open('/tmp/lol', 'wb') -> 00000000
    [2013-05-31 17:17:42,308] [greenio.py:280] [30353/dispatch0] 32756
    [2013-05-31 17:17:42,309] [greenio.py:280] [30353/dispatch0] 132
    [2013-05-31 17:17:42,309] [greenio.py:280] [30353/dispatch0] 32756
    [2013-05-31 17:17:42,310] [greenio.py:280] [30353/dispatch0] 32756
    [2013-05-31 17:17:42,310] [greenio.py:280] [30353/dispatch0] 132
    [2013-05-31 17:17:42,311] [greenio.py:280] [30353/dispatch0] 32756
    [2013-05-31 17:17:42,311] [greenio.py:280] [30353/dispatch0] 132
    [2013-05-31 17:17:42,311] [greenio.py:280] [30353/dispatch0] 32756
    [2013-05-31 17:17:42,311] [greenio.py:280] [30353/dispatch0] 132
    [2013-05-31 17:17:42,312] [greenio.py:280] [30353/dispatch0] 32756
    [2013-05-31 17:17:42,312] [greenio.py:280] [30353/dispatch0] 32756
    [2013-05-31 17:17:42,312] [greenio.py:280] [30353/dispatch0] 132
    [2013-05-31 17:17:42,313] [greenio.py:280] [30353/dispatch0] 32756
    [2013-05-31 17:17:42,313] [greenio.py:280] [30353/dispatch0] 132
    [2013-05-31 17:17:42,314] [greenio.py:280] [30353/dispatch0] 32756
    [2013-05-31 17:17:42,314] [greenio.py:280] [30353/dispatch0] 132
    [2013-05-31 17:17:42,314] [greenio.py:280] [30353/dispatch0] 32756
    [2013-05-31 17:17:42,315] [greenio.py:280] [30353/dispatch0] 132
    [2013-05-31 17:17:42,315] [greenio.py:280] [30353/dispatch0] 32756
    [2013-05-31 17:17:42,315] [greenio.py:280] [30353/dispatch0] 132
    [2013-05-31 17:17:42,315] [greenio.py:280] [30353/dispatch0] 12356
    [2013-05-31 17:17:42,316] [sftp.py:132] [30353/dispatch0] [chan 1] close(00000000)
    [2013-05-31 17:17:42,316] [greenio.py:280] [30353/dispatch0] 68
    [2013-05-31 17:17:43,165] [sftp.py:132] [30353/dispatch0] [chan 1] stat('/tmp/lol')
    [2013-05-31 17:17:43,165] [greenio.py:280] [30353/dispatch0] 68
    

    The difference seems to be that in the good test, it sends 132 bytes after every 32756 max packet, and doesn't deviate away from this pattern much. In the bad test, there are blocks of 5x 32756 max packet, followed by a batch of 132..

    To figure out what 132 was, I force raise an exception in eventlet send() and print the exception, as letting the exception follow through loses context;

      File "/usr/local/lib/python2.6/dist-packages/eventlet-0.12.1-py2.6.egg/eventlet/greenthread.py", line 194, in main
        result = function(*args, **kwargs)
      File "adapters.py", line 312, in on_start
        self.upload_file("/tmp/lol", "/tmp/lol")
      File "adapters.py", line 252, in upload_file
        print sftp.put(local_path, remote_path)
      File "/usr/local/lib/python2.6/dist-packages/paramiko-1.10.1-py2.6.egg/paramiko/sftp_client.py", line 615, in put
        return self.putfo(fl, remotepath, os.stat(localpath).st_size, callback, confirm)
      File "/usr/local/lib/python2.6/dist-packages/paramiko-1.10.1-py2.6.egg/paramiko/sftp_client.py", line 570, in putfo
        fr.write(data)
      File "/usr/local/lib/python2.6/dist-packages/paramiko-1.10.1-py2.6.egg/paramiko/file.py", line 314, in write
        self._write_all(data)
      File "/usr/local/lib/python2.6/dist-packages/paramiko-1.10.1-py2.6.egg/paramiko/file.py", line 439, in _write_all
        count = self._write(data)
      File "/usr/local/lib/python2.6/dist-packages/paramiko-1.10.1-py2.6.egg/paramiko/sftp_file.py", line 168, in _write
        self._reqs.append(self.sftp._async_request(type(None), CMD_WRITE, self.handle, long(self._realpos), str(data[:chunk])))
      File "/usr/local/lib/python2.6/dist-packages/paramiko-1.10.1-py2.6.egg/paramiko/sftp_client.py", line 710, in _async_request
        self._send_packet(t, str(msg))
      File "/usr/local/lib/python2.6/dist-packages/paramiko-1.10.1-py2.6.egg/paramiko/sftp.py", line 172, in _send_packet
        self._write_all(out)
      File "/usr/local/lib/python2.6/dist-packages/paramiko-1.10.1-py2.6.egg/paramiko/sftp.py", line 136, in _write_all
        n = self.sock.send(out)
      File "/usr/local/lib/python2.6/dist-packages/paramiko-1.10.1-py2.6.egg/paramiko/channel.py", line 734, in send
        self.transport._send_user_message(m)
      File "/usr/local/lib/python2.6/dist-packages/paramiko-1.10.1-py2.6.egg/paramiko/transport.py", line 1444, in _send_user_message
        self._send_message(data)
      File "/usr/local/lib/python2.6/dist-packages/paramiko-1.10.1-py2.6.egg/paramiko/transport.py", line 1424, in _send_message
        self.packetizer.send_message(data)
      File "/usr/local/lib/python2.6/dist-packages/paramiko-1.10.1-py2.6.egg/paramiko/packet.py", line 319, in send_message
        self.write_all(out)
      File "/usr/local/lib/python2.6/dist-packages/paramiko-1.10.1-py2.6.egg/paramiko/packet.py", line 248, in write_all
        n = self.__socket.send(out)
      File "/usr/local/lib/python2.6/dist-packages/eventlet-0.12.1-py2.6.egg/eventlet/greenio.py", line 279, in send
        print traceback.print_stack()
    None
    

    So this logic seems to come from;

      File "/usr/local/lib/python2.6/dist-packages/paramiko-1.10.1-py2.6.egg/paramiko/sftp_file.py", line 168, in _write
        self._reqs.append(self.sftp._async_request(type(None), CMD_WRITE, self.handle, long(self._realpos), str(data[:chunk])))
      File "/usr/local/lib/python2.6/dist-packages/paramiko-1.10.1-py2.6.egg/paramiko/sftp_client.py", line 710, in _async_request
        self._send_packet(t, str(msg))
    

    I tried changing the MAX_REQUEST_SIZE, both higher and lower, no effect.

    I just sadly don't understand enough about how paramiko works :/

    Cal

  4. foxx commented on May 31, 2013

    @foxx
    Author

    Okay so, when a packet hits paramiko _write(), the chunk size is 32768. By the time it hits eventlet send(), its 32756, which means there are 12 bytes missing somewhere. Once it hits _async_request, the size is still 32768. Once it hits paramiko _send_packet, the packet size is 32797 due to struct.pack().

    The next step in the stack is channel.py:send(), which then calls self.transport._send_user_message. There is also some other interesting locking/send window stuff going on in here. This waits for a lock and then executes _send_message, which seems to be where the encryption magic happens. This calls write_all(), at which point the packet size is then 32756 (so I guess something in the encryption compressed it down?)

    From here, it seems that socket.timeout is being raised with the following

    Traceback (most recent call last):
      File "/usr/local/lib/python2.6/dist-packages/paramiko-1.10.1-py2.6.egg/paramiko/packet.py", line 248, in write_all
        n = self.__socket.send(out)
      File "/usr/local/lib/python2.6/dist-packages/eventlet-0.12.1-py2.6.egg/eventlet/greenio.py", line 290, in send
        timeout_exc=socket.timeout("timed out"))
      File "/usr/local/lib/python2.6/dist-packages/eventlet-0.12.1-py2.6.egg/eventlet/hubs/__init__.py", line 121, in trampoline
        return hub.switch()
      File "/usr/local/lib/python2.6/dist-packages/eventlet-0.12.1-py2.6.egg/eventlet/hubs/hub.py", line 187, in switch
        return self.greenlet.switch()
    timeout: timed out
    

    The line causing this in eventlet is;

                trampoline(self.fd, write=True, timeout=self.gettimeout(),
                        timeout_exc=socket.timeout("timed out"))
    

    I don't think I can dig up any more from this :(

  5. bitprophet commented on Sep 11, 2014

    @bitprophet
    Member

    See #389.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions