Python: subprocess running rsync causes broken socket in telnetlib

David Antliff david.antliff@gmail.com
Fri Nov 12 03:20:00 GMT 2010


I'm reporting a problem I see on Cygwin because I do not see the same
behaviour on Ubuntu Linux - both systems are running Python 2.6.5.

I have a script that opens a long-term telnet connection (telnetlib)
to a remote host. There is an object called Telnet().socket that is
created and represents an active socket connection to the remote host,
once the right telnetlib calls are made.

Then the script uses subprocess to do something else (the line is
actually longer than this but I've simplified it to the most basic
version that exhibits the problem):

    process = subprocess.Popen("rsync", stdout=subprocess.PIPE)

On Cygwin 1.7.7, this does something nasty to the completely unrelated
yet existing telnetlib socket so that any further attempts to read or
write from this socket raise an exception:

  File "/usr/lib/python2.6/telnetlib.py", line 280, in write
    self.sock.sendall(buffer)
  File "<string>", line 1, in sendall
socket.error: [Errno 32] Broken pipe

On Linux, this doesn't happen at all.

I've tried a few other programs via subprocess like "cat" and "ssh"
but they don't seem to cause this problem - only "rsync" does so far.
There may be others but I haven't found them.

If anyone is prepared to look into this I have attached a small python
script (bug.py) that demonstrates the problem. The error returned in
this case is "113: Software caused connection abort", but the end
result is the same - the socket is broken by the call to subprocess &
rsync:

$ python bug.py
('telnet', '220 mx.google.com ESMTP w42sm3212723wfh.15\r\n')
('ssh', 0, 'OpenSSH_5.6p1, OpenSSL 0.9.8o 01 Jun 2010\n')
('telnet', '250-mx.google.com at your service, [202.27.34.1]\r\n')
('rsync', 0, 'rsync  version 3.0.7  protocol version 30\nCopyright (C) 1996')
Traceback (most recent call last):
  File "bug.py", line 38, in <module>
    print("telnet", t.read_eager())
  File "/usr/lib/python2.6/telnetlib.py", line 370, in read_eager
    self.fill_rawq()
  File "/usr/lib/python2.6/telnetlib.py", line 516, in fill_rawq
    buf = self.sock.recv(50)
socket.error: [Errno 113] Software caused connection abort

If you edit the script and set 'crash' to False, you'll see that the
script completes without error:

$ python bug.py
('telnet', '220 mx.google.com ESMTP i16sm3108013ibl.0\r\n')
('ssh', 0, 'OpenSSH_5.6p1, OpenSSL 0.9.8o 01 Jun 2010\n')
('telnet', '250-mx.google.com at your service, [202.27.34.1]\r\n')
('telnet', '250-SIZE 35651584\r\n250-8BITMIME\r\n250-STARTTLS\r\n250')

And on Linux:

$ python bug.py
('telnet', '220 mx.google.com ESMTP i16sm3106343ibl.18\r\n')
('ssh', 0, 'OpenSSH_5.3p1 Debian-3ubuntu4, OpenSSL 0.9.8k 25 Mar 2009\n')
('telnet', '250-mx.google.com at your service, [202.27.34.1]\r\n')
('rsync', 0, 'rsync  version 3.0.7  protocol version 30\nCopyright (C) 1996')
('telnet', '250-SIZE 35651584\r\n250-8BITMIME\r\n250-STARTTLS\r\n250')


rsync is version 3.0.7.

-- David.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: bug.py
Type: text/x-python
Size: 1191 bytes
Desc: not available
URL: <http://cygwin.com/pipermail/cygwin/attachments/20101112/78f8e84f/attachment.py>
-------------- next part --------------
--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple


More information about the Cygwin mailing list