Skip to content

Commit 94241b9

Browse files
committed
On FreeBSD, avoid a crash caused by buggy socket.connect() in python pre-2.5.
Bug reported by Ed Maste. The fix in later versions of python is documented here: http://mail.python.org/pipermail/python-bugs-list/2006-August/034667.html We're basically just doing the same thing when we see EINVAL. Note that this doesn't happen on Linux because connect() is more forgiving.
1 parent 9031de1 commit 94241b9

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

ssnet.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,16 @@ def try_connect(self):
130130
self.connect_to = None
131131
except socket.error, e:
132132
debug3('%r: connect result: %s\n' % (self, e))
133+
if e.args[0] == errno.EINVAL:
134+
# this is what happens when you call connect() on a socket
135+
# that is now connected but returned EINPROGRESS last time,
136+
# on BSD, on python pre-2.5.1. We need to use getsockopt()
137+
# to get the "real" error. Later pythons do this
138+
# automatically, so this code won't run.
139+
realerr = self.rsock.getsockopt(socket.SOL_SOCKET,
140+
socket.SO_ERROR)
141+
e = socket.error(realerr, os.strerror(realerr))
142+
debug3('%r: fixed connect result: %s\n' % (self, e))
133143
if e.args[0] in [errno.EINPROGRESS, errno.EALREADY]:
134144
pass # not connected yet
135145
elif e.args[0] == errno.EISCONN:

0 commit comments

Comments
 (0)