Skip to content

Commit

Permalink
Fix exception raising in create_connection()
Browse files Browse the repository at this point in the history
The create_connection() function could raise a
socket.error instance, where the errno was the actual
socket.error instance.

Fixes eventlet#168
  • Loading branch information
Donagh McCabe committed Feb 12, 2015
1 parent 5ec3a3c commit d30b236
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions eventlet/green/socket.py
Expand Up @@ -53,9 +53,9 @@ def create_connection(address,
sock.connect(sa)
return sock

except error as e:
msg = e
except error:
if sock is not None:
sock.close()
raise

raise error(msg)
8 changes: 8 additions & 0 deletions tests/test__socket_errors.py
Expand Up @@ -52,5 +52,13 @@ def test_timeout(self, socket=socket):
cs.close()
server.close()

def test_create_connection_refused(self):
try:
s = socket.create_connection(('localhost', 0))
self.fail("Shouldn't have connected")
except socket.error as ex:
assert ex.errno in [111, 61, 10061]


if __name__ == '__main__':
unittest.main()

0 comments on commit d30b236

Please sign in to comment.