diff --git a/lbry/file/file_manager.py b/lbry/file/file_manager.py index ec18d273d..cf4dfe5ec 100644 --- a/lbry/file/file_manager.py +++ b/lbry/file/file_manager.py @@ -283,4 +283,4 @@ class FileManager: async def delete(self, source: ManagedDownloadSource, delete_file=False): for manager in self.source_managers.values(): - return await manager.delete(source, delete_file) + await manager.delete(source, delete_file) diff --git a/lbry/stream/stream_manager.py b/lbry/stream/stream_manager.py index 3c8fcf57b..8df388452 100644 --- a/lbry/stream/stream_manager.py +++ b/lbry/stream/stream_manager.py @@ -231,12 +231,14 @@ class StreamManager(SourceManager): return stream async def delete(self, source: ManagedDownloadSource, delete_file: Optional[bool] = False): - if source.sd_hash in self.running_reflector_uploads: - self.running_reflector_uploads[source.sd_hash].cancel() + if not isinstance(source, ManagedStream): + return + if source.identifier in self.running_reflector_uploads: + self.running_reflector_uploads[source.identifier].cancel() source.stop_tasks() - if source.sd_hash in self.streams: - del self.streams[source.sd_hash] - blob_hashes = [source.sd_hash] + [b.blob_hash for b in source.descriptor.blobs[:-1]] + if source.identifier in self.streams: + del self.streams[source.identifier] + blob_hashes = [source.identifier] + [b.blob_hash for b in source.descriptor.blobs[:-1]] await self.blob_manager.delete_blobs(blob_hashes, delete_from_db=False) await self.storage.delete_stream(source.descriptor) if delete_file and source.output_file_exists: diff --git a/lbry/torrent/session.py b/lbry/torrent/session.py index d714bdbfb..e119583ed 100644 --- a/lbry/torrent/session.py +++ b/lbry/torrent/session.py @@ -63,6 +63,11 @@ class TorrentHandle: self.size = 0 self.total_wanted_done = 0 self.name = '' + self.tasks = [] + + def stop_tasks(self): + while self.tasks: + self.tasks.pop().cancel() def _show_status(self): # fixme: cleanup @@ -177,12 +182,13 @@ class TorrentSession: await self._loop.run_in_executor( self._executor, self._add_torrent, btih, download_path ) - self._loop.create_task(self._handles[btih].status_loop()) + self._handles[btih].tasks.append(self._loop.create_task(self._handles[btih].status_loop())) await self._handles[btih].metadata_completed.wait() def remove_torrent(self, btih, remove_files=False): if btih in self._handles: handle = self._handles[btih] + handle.stop_tasks() self._session.remove_torrent(handle._handle, 1 if remove_files else 0) self._handles.pop(btih) diff --git a/tests/integration/datanetwork/test_file_commands.py b/tests/integration/datanetwork/test_file_commands.py index 095d70765..bbc0dca55 100644 --- a/tests/integration/datanetwork/test_file_commands.py +++ b/tests/integration/datanetwork/test_file_commands.py @@ -53,6 +53,9 @@ class FileCommands(CommandTestCase): self.assertIn(new_btih, self.client_session._handles) self.assertNotIn(btih, self.client_session._handles) self.assertItemCount(await self.daemon.jsonrpc_file_list(), 1) + await self.daemon.jsonrpc_file_delete(delete_all=True) + self.assertItemCount(await self.daemon.jsonrpc_file_list(), 0) + self.assertNotIn(new_btih, self.client_session._handles) async def create_streams_in_range(self, *args, **kwargs): self.stream_claim_ids = []