Skip to content

fix: remove DataStore add-core listener on close()#1282

Merged
RangerMauve merged 1 commit into
mainfrom
fix/datastore-remove-add-core-listener
Jun 11, 2026
Merged

fix: remove DataStore add-core listener on close()#1282
RangerMauve merged 1 commit into
mainfrom
fix/datastore-remove-add-core-listener

Conversation

@gmaclennan

Copy link
Copy Markdown
Member

Fixes #1277.

DataStore registered a permanent add-core listener on the CoreManager but never removed it on close(). If coreManager emitted add-core after the DataStore's MultiCoreIndexer had closed (a teardown racing with a sync session or peer connection adding a core), the listener called addCore() on a closed indexer, throwing Cannot add core after closing from inside a synchronous EventEmitter callback (uncaught).

In CoMapeo mobile this latched the embedded backend into a permanent ERROR state, which the frontend then re-threw on every subsequent RPC send — a storm of fatal/ErrorBoundary crashes (Sentry COMAPEO-20J / 20H / 213).

Changes

  • Store the bound add-core listener as a private field and coreManager.off('add-core', …) it in close() before closing the indexer.
  • Regression test: close() removes the add-core listener (listenerCount returns to baseline).

Related

🤖 Generated with Claude Code

DataStore registered a permanent 'add-core' listener on the CoreManager
but never removed it on close(). If coreManager emitted 'add-core' after
the DataStore's MultiCoreIndexer had closed (a teardown racing with a
sync session or peer connection adding a core), the listener called
addCore() on a closed indexer, throwing 'Cannot add core after closing'
from inside a synchronous EventEmitter callback (uncaught).

Keep a reference to the bound listener and remove it in close() before
closing the indexer.

Closes #1277

@RangerMauve RangerMauve left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good overall

@gmaclennan

Copy link
Copy Markdown
Member Author

@RangerMauve thoughts on why the windows workflow is timing out? It seems like this normally completes in about 9 mins, but I've re-run it 3 times and it keeps failing here. Not sure what in this PR would change things, but maybe it's a github infra issue and these machines are just running slow today? In which case should we increase our timeout?

@RangerMauve

Copy link
Copy Markdown
Contributor

I think it's just that one test that's flaky. Unsure if their infra is just slower right now and its surfacing a race condition somewhere. Defs not related to this PR though.

@RangerMauve RangerMauve merged commit e39ef6d into main Jun 11, 2026
25 of 29 checks passed
@RangerMauve RangerMauve deleted the fix/datastore-remove-add-core-listener branch June 11, 2026 16:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DataStore does not remove its 'add-core' listener on close(), throwing 'Cannot add core after closing' during teardown

2 participants