diff --git a/lbrynet/blob_exchange/downloader.py b/lbrynet/blob_exchange/downloader.py index 7aff3bfaa..b8b854a49 100644 --- a/lbrynet/blob_exchange/downloader.py +++ b/lbrynet/blob_exchange/downloader.py @@ -53,7 +53,7 @@ class BlobDownloader: log.debug("keep peer %s:%i", peer.address, peer.tcp_port) self.failures[peer] = 0 self.connections[peer] = transport - elapsed = self.loop.time - start + elapsed = self.loop.time() - start self.scores[peer] = bytes_received / elapsed if bytes_received and elapsed else 0 async def new_peer_or_finished(self): diff --git a/lbrynet/stream/stream_manager.py b/lbrynet/stream/stream_manager.py index b7fe6734a..6fe849df5 100644 --- a/lbrynet/stream/stream_manager.py +++ b/lbrynet/stream/stream_manager.py @@ -397,12 +397,17 @@ class StreamManager: if not stream.descriptor: raise DownloadSDTimeout(stream.sd_hash) raise DownloadDataTimeout(stream.sd_hash) - if to_replace: # delete old stream now that the replacement has started downloading - await self.delete_stream(to_replace) - stream.set_claim(resolved, claim) - await self.storage.save_content_claim(stream.stream_hash, outpoint) - self.streams[stream.sd_hash] = stream + finally: + if stream.descriptor: + if to_replace: # delete old stream now that the replacement has started downloading + await self.delete_stream(to_replace) + stream.set_claim(resolved, claim) + await self.storage.save_content_claim(stream.stream_hash, outpoint) + self.streams[stream.sd_hash] = stream return stream + except DownloadDataTimeout as err: # forgive data timeout, dont delete stream + error = err + raise except Exception as err: error = err if stream and stream.descriptor: diff --git a/tests/integration/test_file_commands.py b/tests/integration/test_file_commands.py index 2876140a7..419afd8cf 100644 --- a/tests/integration/test_file_commands.py +++ b/tests/integration/test_file_commands.py @@ -79,12 +79,12 @@ class FileCommands(CommandTestCase): blob_hash for blob_hash in self.server.blob_manager.completed_blob_hashes if blob_hash != sd_hash ] await self.server.blob_manager.delete_blobs(all_except_sd) - resp = await self.daemon.jsonrpc_get('lbry://foo', timeout=2) + resp = await self.daemon.jsonrpc_get('lbry://foo', timeout=2, save_file=True) self.assertIn('error', resp) self.assertEqual('Failed to download data blobs for sd hash %s within timeout' % sd_hash, resp['error']) - await self.daemon.jsonrpc_file_delete(claim_name='foo') + self.assertTrue(await self.daemon.jsonrpc_file_delete(claim_name='foo'), "data timeout didnt create a file") await self.server.blob_manager.delete_blobs([sd_hash]) - resp = await self.daemon.jsonrpc_get('lbry://foo', timeout=2) + resp = await self.daemon.jsonrpc_get('lbry://foo', timeout=2, save_file=True) self.assertIn('error', resp) self.assertEqual('Failed to download sd blob %s within timeout' % sd_hash, resp['error'])