This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Python: subprocess running rsync causes broken socket in telnetlib


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.
#!/usr/bin/python
"""
Script to demonstrate how combination of subprocess & rsync causes a telnetlib connection to fail.
David Antliff, Nov 2010
"""
import telnetlib
import subprocess
import time

# ******** change this to False to avoid the crash
crash = True

# Use Google's SMTP server as a demonstration
host = "smtp.gmail.com"
port = 25

# connect to a remote host with telnetlib
t = telnetlib.Telnet()
t.open(host, port)
time.sleep(1)
print("telnet", t.read_eager())

# THE FOLLOWING LINE DOES NOT SEEM TO CAUSE A PROBLEM
process = subprocess.Popen(["ssh", "-V"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
output = process.communicate()[0]
retcode = process.returncode
print("ssh", retcode, output)

# query the telnet server
t.write("EHLO\r\n")
time.sleep(1)
print("telnet", t.read_eager())

if crash:
    # THE FOLLOWING LINE KILLS THE telnetlib SOCKET
    process = subprocess.Popen(["rsync", "--version"], stdout=subprocess.PIPE)
    output = process.communicate()[0]
    retcode = process.returncode
    print("rsync", retcode, output[0:60])

# this will now result in a crash because the connection is lost:
print("telnet", t.read_eager())
t.write("QUIT\r\n")
t.close()

--
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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]