forked from LBRYCommunity/lbry-sdk
fix cancelled blob request?
This commit is contained in:
parent
e50ade85be
commit
b6e9aa420c
2 changed files with 11 additions and 6 deletions
|
@ -4,6 +4,7 @@ from decimal import Decimal
|
||||||
|
|
||||||
from twisted.internet import defer
|
from twisted.internet import defer
|
||||||
from twisted.python.failure import Failure
|
from twisted.python.failure import Failure
|
||||||
|
from twisted.internet.error import ConnectionAborted
|
||||||
from zope.interface import implements
|
from zope.interface import implements
|
||||||
|
|
||||||
from lbrynet.core.Error import ConnectionClosedBeforeResponseError
|
from lbrynet.core.Error import ConnectionClosedBeforeResponseError
|
||||||
|
@ -225,7 +226,7 @@ class RequestHelper(object):
|
||||||
self.requestor._update_local_score(self.peer, score)
|
self.requestor._update_local_score(self.peer, score)
|
||||||
|
|
||||||
def _request_failed(self, reason, request_type):
|
def _request_failed(self, reason, request_type):
|
||||||
if reason.check(RequestCanceledError):
|
if reason.check(DownloadCanceledError, RequestCanceledError, ConnectionAborted):
|
||||||
return
|
return
|
||||||
if reason.check(NoResponseError):
|
if reason.check(NoResponseError):
|
||||||
self.requestor._incompatible_peers.append(self.peer)
|
self.requestor._incompatible_peers.append(self.peer)
|
||||||
|
|
|
@ -134,6 +134,7 @@ class ClientProtocol(Protocol, TimeoutMixin):
|
||||||
self._blob_download_request.cancel(err)
|
self._blob_download_request.cancel(err)
|
||||||
ds.append(self._blob_download_request.finished_deferred)
|
ds.append(self._blob_download_request.finished_deferred)
|
||||||
self._blob_download_request = None
|
self._blob_download_request = None
|
||||||
|
self._downloading_blob = False
|
||||||
return defer.DeferredList(ds)
|
return defer.DeferredList(ds)
|
||||||
|
|
||||||
######### Internal request handling #########
|
######### Internal request handling #########
|
||||||
|
@ -191,21 +192,24 @@ class ClientProtocol(Protocol, TimeoutMixin):
|
||||||
|
|
||||||
def _handle_response_error(self, err):
|
def _handle_response_error(self, err):
|
||||||
# If an error gets to this point, log it and kill the connection.
|
# If an error gets to this point, log it and kill the connection.
|
||||||
if err.check(DownloadCanceledError, RequestCanceledError):
|
if err.check(DownloadCanceledError, RequestCanceledError, error.ConnectionAborted):
|
||||||
# TODO: (wish-list) it seems silly to close the connection over this, and it shouldn't
|
# TODO: (wish-list) it seems silly to close the connection over this, and it shouldn't
|
||||||
# TODO: always be this way. it's done this way now because the client has no other way
|
# TODO: always be this way. it's done this way now because the client has no other way
|
||||||
# TODO: of telling the server it wants the download to stop. It would be great if the
|
# TODO: of telling the server it wants the download to stop. It would be great if the
|
||||||
# TODO: protocol had such a mechanism.
|
# TODO: protocol had such a mechanism.
|
||||||
log.info("Closing the connection to %s because the download of blob %s was canceled",
|
log.info("Closing the connection to %s because the download of blob %s was canceled",
|
||||||
self.peer, self._blob_download_request.blob)
|
self.peer, self._blob_download_request.blob)
|
||||||
return
|
result = None
|
||||||
elif not err.check(MisbehavingPeerError, ConnectionClosedBeforeResponseError):
|
elif not err.check(MisbehavingPeerError, ConnectionClosedBeforeResponseError):
|
||||||
log.warning("The connection to %s is closing due to: %s", err)
|
log.warning("The connection to %s is closing due to: %s", err)
|
||||||
return err
|
result = err
|
||||||
else:
|
else:
|
||||||
log.error("The connection to %s is closing due to an unexpected error: %s",
|
log.error("The connection to %s is closing due to an unexpected error: %s",
|
||||||
self.peer, err)
|
self.peer, err)
|
||||||
return err
|
result = err
|
||||||
|
|
||||||
|
self.transport.loseConnection()
|
||||||
|
return result
|
||||||
|
|
||||||
def _handle_response(self, response):
|
def _handle_response(self, response):
|
||||||
ds = []
|
ds = []
|
||||||
|
@ -246,7 +250,7 @@ class ClientProtocol(Protocol, TimeoutMixin):
|
||||||
log.debug("Asking for another request from %s", self.peer)
|
log.debug("Asking for another request from %s", self.peer)
|
||||||
self._ask_for_request()
|
self._ask_for_request()
|
||||||
else:
|
else:
|
||||||
log.debug("Not asking for another request from %s", self.peer)
|
log.warning("Not asking for another request from %s", self.peer)
|
||||||
self.transport.loseConnection()
|
self.transport.loseConnection()
|
||||||
|
|
||||||
dl.addCallback(get_next_request)
|
dl.addCallback(get_next_request)
|
||||||
|
|
Loading…
Reference in a new issue