Skip to content
This repository was archived by the owner on Jan 13, 2021. It is now read-only.

Commit 88da7c3

Browse files
authored
Merge pull request #326 from obrown/development
Check HTTP11 socket is initialized before closing
2 parents 496f3a0 + 87d10bb commit 88da7c3

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

hyper/http11/connection.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,8 @@ def close(self):
385385
.. warning:: This method should absolutely only be called when you are
386386
certain the connection object is no longer needed.
387387
"""
388-
self._sock.close()
388+
if self._sock is not None:
389+
self._sock.close()
389390
self._sock = None
390391

391392
# The following two methods are the implementation of the context manager

test/test_http11.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,10 @@ def read(self, size):
529529
assert 'File-like bodies must return bytestrings. ' \
530530
'Got: {}'.format(int) in str(exc_info)
531531

532+
def test_close_with_uninitialized_socket(self):
533+
c = HTTP11Connection('httpbin.org')
534+
c.close()
535+
532536

533537
class TestHTTP11Response(object):
534538
def test_short_circuit_read(self):

0 commit comments

Comments
 (0)