# Buggy code
def _request_failed(self, reason, request_type):
    if reason.check(
        DownloadCanceledError,
        RequestCanceledError,
        ConnectionAborted,
        ConnectionClosedBeforeResponseError,
    ):
        return
    if reason.check(NoResponseError):
        self.requestor._incompatible_peers.append(self.peer)
    log.warning(
        "A request of type '%s' failed. Reason: %s, Error type: %s",
        request_type,
        reason.getErrorMessage(),
        reason.type,
    )
    self.update_local_score(-10.0)
    if isinstance(reason, (InvalidResponseError, NoResponseError)):
        self.peer.update_score(-10.0)
    else:
        self.peer.update_score(-2.0)
    if reason.check(ConnectionClosedBeforeResponseError):
        return
    return reason


# Traceback (exceptions.ValueError)
2017-10-12 13:52:54,172 INFO     lbrynet.core.client.ClientProtocol:185: Closing the connection to x.x.x.x:3333 because the download of blob a5d1ebd863d2b5f7 was canceled
2017-10-12 13:52:54,174 ERROR    lbrynet.core.client.ClientProtocol:130: An unexpected error occurred creating or sending a request to x.x.x.x:3333. Error message: Traceback (most recent call last):
File "site-packages/twisted/internet/defer.py", line 651, in _runCallbacks
File "site-packages/lbrynet/core/client/ClientProtocol.py", line 235, in get_next_request
File "site-packages/lbrynet/core/client/ClientProtocol.py", line 147, in _ask_for_request
File "site-packages/twisted/internet/defer.py", line 1445, in unwindGenerator
--- <exception caught here> ---
File "site-packages/twisted/internet/defer.py", line 1299, in _inlineCallbacks
File "site-packages/lbrynet/core/client/ConnectionManager.py", line 111, in get_next_request
File "site-packages/lbrynet/core/client/ConnectionManager.py", line 137, in _send_primary_requests
File "site-packages/lbrynet/core/client/BlobRequester.py", line 66, in send_next_request
File "site-packages/lbrynet/core/client/BlobRequester.py", line 113, in _send_next_request
File "site-packages/lbrynet/core/client/BlobRequester.py", line 440, in make_request_and_handle_response
File "site-packages/lbrynet/core/client/BlobRequester.py", line 493, in _handle_download_request
File "site-packages/lbrynet/core/client/BlobRequester.py", line 540, in create_add_blob_request
File "site-packages/lbrynet/core/client/ClientProtocol.py", line 108, in add_blob_request
exceptions.ValueError: There is already a blob download request active

# Fixed code
def _request_failed(self, reason, request_type):
    if reason.check(
        DownloadCanceledError,
        RequestCanceledError,
        ConnectionAborted,
        ConnectionClosedBeforeResponseError,
        ValueError,
    ):
        return
    if reason.check(NoResponseError):
        self.requestor._incompatible_peers.append(self.peer)
    log.warning(
        "A request of type '%s' failed. Reason: %s, Error type: %s",
        request_type,
        reason.getErrorMessage(),
        reason.type,
    )
    self.update_local_score(-10.0)
    if isinstance(reason, (InvalidResponseError, NoResponseError)):
        self.peer.update_score(-10.0)
    else:
        self.peer.update_score(-2.0)
    return reason