aboutsummaryrefslogtreecommitdiffstats
path: root/packages/meshbay-node/src/meshbay_node/indexer
diff options
context:
space:
mode:
authorChristophe Besson <cbesson@gmail.com>2026-09-14 09:40:23 +0200
committerChristophe Besson <cbesson@gmail.com>2026-09-14 09:40:23 +0200
commitd4b37774118a2689c67b2ad802b9763f2ef448fd (patch)
tree22a287709879f822cc3751842804f2c64c6a80d4 /packages/meshbay-node/src/meshbay_node/indexer
parent211ace6cc0168647e00bcc20a909aead50b8ad0a (diff)
downloadmeshbay-d4b37774118a2689c67b2ad802b9763f2ef448fd.tar.gz
fix(node): a reload and a plug rescan outlive the session that asked
A root added from the client arrives over MNP, and _retarget_indexer started the daemon's reload with the session's own _spawn. When that session closed - a client reconnecting 47 s into the scan of a 900 GB root - shutdown_tasks() cancelled the reload mid-scan, and the reload queued behind it, without a line in the log. The new root was in node.toml and in the indexer's set but never in the group's context; the lock was free and nothing retried, so the node served the old roots table for hours while reconcile hashed the whole drive as missed events. One loopback reload fixed the live node in 9 ms. _reload_config now runs the work in a node-owned task and awaits it through asyncio.shield, so a caller that goes away only stops waiting; a cancelled reload is logged. plug_root does the same for its rescan, which drops the root's entries before walking the disk and so left the root empty when its admin op's session closed. The existing MNP test replaced _spawn with a list and could not cancel anything; the new tests close the session for real and fail without this. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01T6jPTeocXA1BePekdsgPya
Diffstat (limited to 'packages/meshbay-node/src/meshbay_node/indexer')
-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()