diff --git a/lbrynet/extras/daemon/Daemon.py b/lbrynet/extras/daemon/Daemon.py index 3b42e7164..aa4c3606e 100644 --- a/lbrynet/extras/daemon/Daemon.py +++ b/lbrynet/extras/daemon/Daemon.py @@ -1511,7 +1511,7 @@ class Daemon(metaclass=JSONRPCServerType): raise Exception(f'Unable to find a file for {kwargs}') stream = streams[0] if status == 'start' and not stream.running: - await self.stream_manager.start_stream(stream) + await stream.save_file(node=self.stream_manager.node) msg = "Resumed download" elif status == 'stop' and stream.running: await stream.stop() diff --git a/lbrynet/stream/managed_stream.py b/lbrynet/stream/managed_stream.py index 21e6d0368..1a1221546 100644 --- a/lbrynet/stream/managed_stream.py +++ b/lbrynet/stream/managed_stream.py @@ -5,7 +5,7 @@ import logging import binascii from aiohttp.web import Request, StreamResponse from lbrynet.utils import generate_id -from lbrynet.error import DownloadSDTimeout, DownloadDataTimeout +from lbrynet.error import DownloadSDTimeout from lbrynet.schema.mime_types import guess_media_type from lbrynet.stream.downloader import StreamDownloader from lbrynet.stream.descriptor import StreamDescriptor @@ -257,17 +257,11 @@ class ManagedStream: return log.info("start downloader for lbry://%s#%s (sd hash %s...)", self.claim_name, self.claim_id, self.sd_hash[:6]) self._running.set() - start_time = self.loop.time() try: await asyncio.wait_for(self.downloader.start(node), timeout, loop=self.loop) - if save_now: - await asyncio.wait_for(self.save_file(node=node), timeout - (self.loop.time() - start_time), - loop=self.loop) except asyncio.TimeoutError: self._running.clear() - if not self.descriptor: - raise DownloadSDTimeout(self.sd_hash) - raise DownloadDataTimeout(self.sd_hash) + raise DownloadSDTimeout(self.sd_hash) if self.delayed_stop_task and not self.delayed_stop_task.done(): self.delayed_stop_task.cancel() diff --git a/lbrynet/stream/stream_manager.py b/lbrynet/stream/stream_manager.py index ac1566d1c..bdf63f137 100644 --- a/lbrynet/stream/stream_manager.py +++ b/lbrynet/stream/stream_manager.py @@ -7,7 +7,7 @@ import random from decimal import Decimal from aiohttp.web import Request from lbrynet.error import ResolveError, InvalidStreamDescriptorError, KeyFeeAboveMaxAllowed, InsufficientFundsError -from lbrynet.error import ResolveTimeout +from lbrynet.error import ResolveTimeout, DownloadDataTimeout from lbrynet.utils import cache_concurrent from lbrynet.stream.descriptor import StreamDescriptor from lbrynet.stream.managed_stream import ManagedStream @@ -375,13 +375,23 @@ class StreamManager: analytics_manager=self.analytics_manager ) log.info("starting download for %s", uri) - await stream.start(self.node, timeout, save_now=save_file) + + before_download = self.loop.time() + await stream.start(self.node, timeout) + stream.set_claim(resolved, claim) if to_replace: # delete old stream now that the replacement has started downloading await self.delete_stream(to_replace) self.streams[stream.sd_hash] = stream - stream.set_claim(resolved, claim) + + self.storage.content_claim_callbacks[stream.stream_hash] = lambda: self._update_content_claim(stream) await self.storage.save_content_claim(stream.stream_hash, outpoint) + if save_file: + await asyncio.wait_for(stream.save_file(node=self.node), timeout - (self.loop.time() - before_download), + loop=self.loop) return stream + except asyncio.TimeoutError: + error = DownloadDataTimeout(stream.sd_hash) + raise error except Exception as err: # forgive data timeout, dont delete stream error = err raise