Break the peerSync <-> peerSyncReceive import cycle by extracting the subscription store to a leaf - #6091
Merged
Merged
Conversation
…nd peerSyncReceive stop importing each other (#5919) peerSync.js and peerSyncReceive.js formed a two-module ESM cycle on the federation path: peerSync statically imported applyIncomingPush while the receiver imported findPeerSubscription/subscribePeer back out of peerSync. In a static cycle whichever module evaluates first sees undefined bindings, so a module-ordering change could turn peer sync into a boot-time crash. The subscription CRUD now lives in sharing/peerSubscriptions.js (a leaf over peerSyncShared/peerTombstoneCursors/peerSyncPush), along with the background-operation registry and the debounce timer map unsubscribePeer has to cancel against. Both peerSync and peerSyncReceive import the declaring module; peerSync keeps re-exporting the surface so outside callers are unchanged. Drops the now-dead peerSyncShared imports peerSync no longer uses.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
sharing/peerSync.jsandsharing/peerSyncReceive.jsstatically imported each other, forming a two-module ESM cycle on the federation path. In a static cycle whichever module evaluates first seesundefinedfor the other's bindings, so a module-ordering change could turn peer sync into a boot-time crash — a cross-machine outage, not a local one.sharing/peerSubscriptions.js:listPeerSubscriptions,findPeerSubscription,getOutboundCoverageForPeer,subscribePeer,unsubscribePeer, plus the background-operation registry and the debounce timer mapunsubscribePeermust cancel against. It imports onlypeerSyncShared,peerTombstoneCursors, andpeerSyncPush— none of which reach back intopeerSync.peerSync.jsandpeerSyncReceive.jsnow import the declaring module.peerSync.jskeeps re-exporting the surface, so every existing deep importer (routes,sharing/index.js, dataSync, tools, tests) is unchanged. Noawait import()— the cycle is removed, not dodged.peerSyncSharedimportspeerSync.jsno longer uses (including two that were already dead:peerSyncEvents,ERR_SCHEMA_VERSION_AHEAD— both still re-exported viaexport … from).KNOWN_CYCLIC_COMPONENTSinserver/services/serviceImportCycles.test.js, so the baseline shrinks.Closes #5919
Test plan
cd server && npx vitest run services/serviceImportCycles.test.js— 5 passed; the cycle guard now holds with the baseline entry removed.cd server && npx vitest run services/sharing/— 22 files, 607 tests passed.cd server && npx vitest run routes/peerSync.test.js routes/peerSyncAuthIntegration.test.js routes/instances.test.js services/syncOrchestrator.test.js services/dataSync— 216 passed.cd server && npm test— 1909 files passed, 38,515 tests passed, 24 skipped.