aboutsummaryrefslogtreecommitdiffstats
path: root/packages/meshbay-node/src/meshbay_node/indexer/indexer.py
diff options
context:
space:
mode:
Diffstat (limited to 'packages/meshbay-node/src/meshbay_node/indexer/indexer.py')
-rw-r--r--packages/meshbay-node/src/meshbay_node/indexer/indexer.py18
1 files changed, 16 insertions, 2 deletions
diff --git a/packages/meshbay-node/src/meshbay_node/indexer/indexer.py b/packages/meshbay-node/src/meshbay_node/indexer/indexer.py
index 2b68550..c20902e 100644
--- a/packages/meshbay-node/src/meshbay_node/indexer/indexer.py
+++ b/packages/meshbay-node/src/meshbay_node/indexer/indexer.py
@@ -953,8 +953,22 @@ class DirectoryIndexer:
return
root.ejected = False
root.available = root.is_live()
- if root.available:
- log.info("Root %r plugged — rescanning", root.name)
+ if not root.available:
+ await self._finish_plug(None)
+ return
+ log.info("Root %r plugged — rescanning", root.name)
+ # `_rescan_root` drops the root's entries before it walks the disk, and
+ # this is called from an admin op running in the operator's WebRTC
+ # session — which cancels everything it started when it closes. So the
+ # rescan runs in a task this indexer owns, and a caller that goes away
+ # only stops waiting for it instead of leaving the root emptied.
+ task = asyncio.create_task(self._finish_plug(root))
+ self._scan_tasks.add(task)
+ task.add_done_callback(self._scan_tasks.discard)
+ await asyncio.shield(task)
+
+ async def _finish_plug(self, root: Root | None) -> None:
+ if root is not None:
await self._rescan_root(root)
self._restart_observer()
self._index.roots = self.roots.describe()