forked from LBRYCommunity/lbry-sdk
catch IOError properly
This commit is contained in:
parent
ea49cddf52
commit
e50ade85be
1 changed files with 16 additions and 6 deletions
|
@ -50,15 +50,20 @@ class ClientProtocol(Protocol, TimeoutMixin):
|
||||||
log.debug("Data receieved from %s", self.peer)
|
log.debug("Data receieved from %s", self.peer)
|
||||||
self.setTimeout(None)
|
self.setTimeout(None)
|
||||||
self._rate_limiter.report_dl_bytes(len(data))
|
self._rate_limiter.report_dl_bytes(len(data))
|
||||||
|
|
||||||
|
def in_case_IOError():
|
||||||
|
#TODO: writes can raise IOError if another peer finished
|
||||||
|
#writing and closes the other peeer's writers. Fix this
|
||||||
|
#by preventing peers from downloading the same blobs
|
||||||
|
msg = "Failed to write, blob is likely closed by another peer finishing download"
|
||||||
|
log.warn(msg)
|
||||||
|
self.transport.loseConnection()
|
||||||
|
|
||||||
if self._downloading_blob is True:
|
if self._downloading_blob is True:
|
||||||
try:
|
try:
|
||||||
self._blob_download_request.write(data)
|
self._blob_download_request.write(data)
|
||||||
except IOError as e:
|
except IOError as e:
|
||||||
#TODO: we need to fix this so that we do not even
|
in_case_IOError()
|
||||||
#attempt to download the same blob from different peers
|
|
||||||
msg = "Failed to write, blob is likely closed by another peer finishing download"
|
|
||||||
log.warn(msg)
|
|
||||||
self.transport.loseConnection()
|
|
||||||
else:
|
else:
|
||||||
self._response_buff += data
|
self._response_buff += data
|
||||||
if len(self._response_buff) > conf.settings['MAX_RESPONSE_INFO_SIZE']:
|
if len(self._response_buff) > conf.settings['MAX_RESPONSE_INFO_SIZE']:
|
||||||
|
@ -70,7 +75,12 @@ class ClientProtocol(Protocol, TimeoutMixin):
|
||||||
self._response_buff = ''
|
self._response_buff = ''
|
||||||
self._handle_response(response)
|
self._handle_response(response)
|
||||||
if self._downloading_blob is True and len(extra_data) != 0:
|
if self._downloading_blob is True and len(extra_data) != 0:
|
||||||
self._blob_download_request.write(extra_data)
|
try:
|
||||||
|
self._blob_download_request.write(extra_data)
|
||||||
|
except IOError as e:
|
||||||
|
in_case_IOError()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def timeoutConnection(self):
|
def timeoutConnection(self):
|
||||||
log.info("Connection timed out to %s", self.peer)
|
log.info("Connection timed out to %s", self.peer)
|
||||||
|
|
Loading…
Reference in a new issue