From d6a6007c258d6a0546c3bcd840d0b11c5c5831a0 Mon Sep 17 00:00:00 2001 From: "V.G. Bulavintsev" Date: Tue, 21 Sep 2021 18:29:38 +0200 Subject: [PATCH] Fix community component shutdown leaving stuff behind --- .../components/implementation/bandwidth_accounting.py | 5 +++-- .../tribler_core/components/implementation/gigachannel.py | 4 ++-- .../tribler_core/components/implementation/ipv8.py | 4 ++++ .../tribler_core/components/implementation/popularity.py | 4 ++-- .../tribler_core/components/implementation/tunnels.py | 4 ++-- .../components/interfaces/bandwidth_accounting.py | 3 +++ .../tribler_core/components/interfaces/gigachannel.py | 3 +++ .../tribler_core/components/interfaces/popularity.py | 3 +++ .../tribler_core/components/interfaces/tunnels.py | 3 +++ 9 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src/tribler-core/tribler_core/components/implementation/bandwidth_accounting.py b/src/tribler-core/tribler_core/components/implementation/bandwidth_accounting.py index 3f44389c7f1..af1509dbd56 100644 --- a/src/tribler-core/tribler_core/components/implementation/bandwidth_accounting.py +++ b/src/tribler-core/tribler_core/components/implementation/bandwidth_accounting.py @@ -1,6 +1,7 @@ from ipv8.peerdiscovery.discovery import RandomWalk from tribler_common.simpledefs import STATEDIR_DB_DIR + from tribler_core.components.interfaces.bandwidth_accounting import BandwidthAccountingComponent from tribler_core.components.interfaces.ipv8 import Ipv8Component from tribler_core.components.interfaces.reporter import ReporterComponent @@ -23,7 +24,7 @@ async def run(self): config = self.session.config ipv8_component = await self.use(Ipv8Component) - ipv8 = ipv8_component.ipv8 + ipv8 = self._ipv8 = ipv8_component.ipv8 peer = ipv8_component.peer rest_manager = self.rest_manager = (await self.use(RESTComponent)).rest_manager @@ -50,4 +51,4 @@ async def run(self): async def shutdown(self): self.rest_manager.get_endpoint('trustview').bandwidth_db = None self.rest_manager.get_endpoint('bandwidth').bandwidth_community = None - await self.community.unload() + await self._ipv8.unload_overlay(self.community) diff --git a/src/tribler-core/tribler_core/components/implementation/gigachannel.py b/src/tribler-core/tribler_core/components/implementation/gigachannel.py index 02ff56f1e1d..543f2cf1a0b 100644 --- a/src/tribler-core/tribler_core/components/implementation/gigachannel.py +++ b/src/tribler-core/tribler_core/components/implementation/gigachannel.py @@ -25,7 +25,7 @@ async def run(self): notifier = self.session.notifier ipv8_component = await self.use(Ipv8Component) - ipv8 = ipv8_component.ipv8 + ipv8 = self._ipv8 = ipv8_component.ipv8 peer = ipv8_component.peer rest_manager = self.rest_manager = (await self.use(RESTComponent)).rest_manager metadata_store = (await self.use(MetadataStoreComponent)).mds @@ -60,4 +60,4 @@ async def shutdown(self): self.rest_manager.get_endpoint('collections').gigachannel_community = None await self.release(RESTComponent) - await self.community.unload() + await self._ipv8.unload_overlay(self.community) diff --git a/src/tribler-core/tribler_core/components/implementation/ipv8.py b/src/tribler-core/tribler_core/components/implementation/ipv8.py index 223149d4a1d..49f67196a54 100644 --- a/src/tribler-core/tribler_core/components/implementation/ipv8.py +++ b/src/tribler-core/tribler_core/components/implementation/ipv8.py @@ -133,6 +133,10 @@ async def shutdown(self): self.rest_manager.get_endpoint('statistics').ipv8 = None await self.release(RESTComponent) + for overlay in (self.dht_discovery_community, self.peer_discovery_community): + if overlay: + await self.ipv8.unload_overlay(overlay) + await self.unused.wait() self.session.notifier.notify_shutdown_state("Shutting down IPv8...") await self.task_manager.shutdown_task_manager() diff --git a/src/tribler-core/tribler_core/components/implementation/popularity.py b/src/tribler-core/tribler_core/components/implementation/popularity.py index fc0670fd87a..6a0cadaec82 100644 --- a/src/tribler-core/tribler_core/components/implementation/popularity.py +++ b/src/tribler-core/tribler_core/components/implementation/popularity.py @@ -17,7 +17,7 @@ async def run(self): config = self.session.config ipv8_component = await self.use(Ipv8Component) - ipv8 = ipv8_component.ipv8 + ipv8 = self._ipv8 = ipv8_component.ipv8 peer = ipv8_component.peer metadata_store = (await self.use(MetadataStoreComponent)).mds @@ -39,4 +39,4 @@ async def run(self): ipv8.overlays.append(community) async def shutdown(self): - await self.community.unload() + await self._ipv8.unload_overlay(self.community) diff --git a/src/tribler-core/tribler_core/components/implementation/tunnels.py b/src/tribler-core/tribler_core/components/implementation/tunnels.py index 126a20a41b4..18eb5ebac9b 100644 --- a/src/tribler-core/tribler_core/components/implementation/tunnels.py +++ b/src/tribler-core/tribler_core/components/implementation/tunnels.py @@ -21,7 +21,7 @@ async def run(self): config = self.session.config ipv8_component = await self.use(Ipv8Component) - ipv8 = ipv8_component.ipv8 + ipv8 = self._ipv8 = ipv8_component.ipv8 peer = ipv8_component.peer dht_discovery_community = ipv8_component.dht_discovery_community @@ -80,4 +80,4 @@ async def run(self): debug_endpoint.tunnel_community = community async def shutdown(self): - await self.community.unload() + await self._ipv8.unload_overlay(self.community) diff --git a/src/tribler-core/tribler_core/components/interfaces/bandwidth_accounting.py b/src/tribler-core/tribler_core/components/interfaces/bandwidth_accounting.py index 070c0dfa331..a03b8427532 100644 --- a/src/tribler-core/tribler_core/components/interfaces/bandwidth_accounting.py +++ b/src/tribler-core/tribler_core/components/interfaces/bandwidth_accounting.py @@ -1,5 +1,7 @@ from unittest.mock import Mock +from ipv8_service import IPv8 + from tribler_core.components.base import Component, testcomponent from tribler_core.config.tribler_config import TriblerConfig from tribler_core.modules.bandwidth_accounting.community import BandwidthAccountingCommunity @@ -8,6 +10,7 @@ class BandwidthAccountingComponent(Component): community: BandwidthAccountingCommunity enable_in_gui_test_mode = True + _ipv8: IPv8 @classmethod def should_be_enabled(cls, config: TriblerConfig): diff --git a/src/tribler-core/tribler_core/components/interfaces/gigachannel.py b/src/tribler-core/tribler_core/components/interfaces/gigachannel.py index 35eed2e0764..f66ba7819b4 100644 --- a/src/tribler-core/tribler_core/components/interfaces/gigachannel.py +++ b/src/tribler-core/tribler_core/components/interfaces/gigachannel.py @@ -1,5 +1,7 @@ from unittest.mock import Mock +from ipv8_service import IPv8 + from tribler_core.components.base import Component, testcomponent from tribler_core.config.tribler_config import TriblerConfig from tribler_core.modules.metadata_store.community.gigachannel_community import GigaChannelCommunity @@ -9,6 +11,7 @@ class GigaChannelComponent(Component): enable_in_gui_test_mode = True community: GigaChannelCommunity + _ipv8: IPv8 @classmethod def should_be_enabled(cls, config: TriblerConfig): diff --git a/src/tribler-core/tribler_core/components/interfaces/popularity.py b/src/tribler-core/tribler_core/components/interfaces/popularity.py index 6f2ed07e0a1..2df84255bd4 100644 --- a/src/tribler-core/tribler_core/components/interfaces/popularity.py +++ b/src/tribler-core/tribler_core/components/interfaces/popularity.py @@ -1,5 +1,7 @@ from unittest.mock import Mock +from ipv8_service import IPv8 + from tribler_core.components.base import Component, testcomponent from tribler_core.config.tribler_config import TriblerConfig from tribler_core.modules.popularity.community import PopularityCommunity @@ -9,6 +11,7 @@ class PopularityComponent(Component): enable_in_gui_test_mode = True community: PopularityCommunity + _ipv8: IPv8 @classmethod def should_be_enabled(cls, config: TriblerConfig): diff --git a/src/tribler-core/tribler_core/components/interfaces/tunnels.py b/src/tribler-core/tribler_core/components/interfaces/tunnels.py index 2103cbc16ec..2c15013e747 100644 --- a/src/tribler-core/tribler_core/components/interfaces/tunnels.py +++ b/src/tribler-core/tribler_core/components/interfaces/tunnels.py @@ -1,5 +1,7 @@ from unittest.mock import Mock +from ipv8_service import IPv8 + from tribler_core.components.base import Component, testcomponent from tribler_core.config.tribler_config import TriblerConfig from tribler_core.modules.tunnel.community.community import TriblerTunnelCommunity @@ -7,6 +9,7 @@ class TunnelsComponent(Component): community: TriblerTunnelCommunity + _ipv8: IPv8 @classmethod def should_be_enabled(cls, config: TriblerConfig):