-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix race connection. also close #105
make sure we are releasing the socket and eventually read the rest of the body.
- Loading branch information
Showing
3 changed files
with
16 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -151,6 +151,8 @@ def __init__(self, resp, connection): | |
self.resp = resp | ||
self.body = resp._body | ||
self.connection = connection | ||
self._closed = False | ||
self.eof = False | ||
|
||
def __enter__(self): | ||
return self | ||
|
@@ -160,7 +162,14 @@ def __exit__(self, exc_type, exc_val, traceback): | |
|
||
def close(self): | ||
""" release connection """ | ||
if self._closed: | ||
return | ||
|
||
if not self.eof: | ||
self.body.read() | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
benoitc
Author
Owner
|
||
|
||
self.connection.release(self.resp.should_close) | ||
self._closed = True | ||
|
||
def __iter__(self): | ||
return self | ||
|
@@ -169,24 +178,28 @@ def next(self): | |
try: | ||
return self.body.next() | ||
except StopIteration: | ||
self.eof = True | ||
self.close() | ||
raise | ||
|
||
def read(self, n=-1): | ||
data = self.body.read(n) | ||
if not data: | ||
self.eof = True | ||
self.close() | ||
return data | ||
|
||
def readline(self, limit=-1): | ||
line = self.body.readline(limit) | ||
if not line: | ||
self.eof = True | ||
self.close() | ||
return line | ||
|
||
def readlines(self, hint=None): | ||
lines = self.body.readlines(hint) | ||
if self.body.close: | ||
self.eof = True | ||
self.close() | ||
return lines | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
this will create quite some trouble for discarded chunked responses
i sense a potential for surprising "deadlocks"