diff --git a/lbry/lbry/blob/blob_file.py b/lbry/lbry/blob/blob_file.py index 45ac2b26f..0492a3844 100644 --- a/lbry/lbry/blob/blob_file.py +++ b/lbry/lbry/blob/blob_file.py @@ -163,7 +163,10 @@ class AbstractBlob: if not self.is_readable(): raise OSError('blob files cannot be read') with self.reader_context() as handle: - return await self.loop.sendfile(writer.transport, handle, count=self.get_length()) + try: + return await self.loop.sendfile(writer.transport, handle, count=self.get_length()) + except (ConnectionResetError, BrokenPipeError, RuntimeError, OSError, AttributeError): + return -1 def decrypt(self, key: bytes, iv: bytes) -> bytes: """ diff --git a/lbry/lbry/blob_exchange/server.py b/lbry/lbry/blob_exchange/server.py index 123351888..15ac046ee 100644 --- a/lbry/lbry/blob_exchange/server.py +++ b/lbry/lbry/blob_exchange/server.py @@ -101,16 +101,21 @@ class BlobServerProtocol(asyncio.Protocol): self.started_transfer.set() try: sent = await asyncio.wait_for(blob.sendfile(self), self.transfer_timeout, loop=self.loop) - self.blob_manager.connection_manager.sent_data(self.peer_address_and_port, sent) - log.info("sent %s (%i bytes) to %s:%i", bh, sent, peer_address, peer_port) - except (ConnectionResetError, BrokenPipeError, RuntimeError, OSError, asyncio.TimeoutError) as err: + if sent and sent > 0: + self.blob_manager.connection_manager.sent_data(self.peer_address_and_port, sent) + log.info("sent %s (%i bytes) to %s:%i", bh, sent, peer_address, peer_port) + else: + log.debug("stopped sending %s to %s:%i", bh, peer_address, peer_port) + except (OSError, asyncio.TimeoutError) as err: if isinstance(err, asyncio.TimeoutError): log.debug("timed out sending blob %s to %s", bh, peer_address) else: - log.debug("stopped sending %s to %s:%i", bh, peer_address, peer_port) + log.warning("could not read blob %s to send %s:%i", bh, peer_address, peer_port) self.close() finally: self.transfer_finished.set() + else: + log.info("don't have %s to send %s:%i", blob.blob_hash[:8], peer_address, peer_port) if responses: self.send_response(responses)