Repository navigation
Share an observe multiplexer while its driver starts - #14
Draft
mark1russell7 wants to merge 1 commit into
Draft
mark1russell7 wants to merge 1 commit into
mark1russell7 wants to merge 1 commit into
Conversation
_observeChanges registered a new multiplexer in _observeMultiplexers only after its driver had started. observeChanges calls for the same cursor that arrived meanwhile each created their own multiplexer and driver, and ran the first query again. The last one to start kept the map entry. onStop deleted the entry without a check, so when an earlier multiplexer stopped, it removed the entry of a live one, and later calls started yet another. The multiplexer is now registered before anything yields, and onStop removes the entry only if it is still this multiplexer. A driver that fails to start now goes to queryError, which removes the multiplexer. queryError now also rejects the ready promise, so every handle waiting on the multiplexer gets the error, and a handle that found the multiplexer before it stopped gets it too. Before, those handles waited for good. The polling driver already left handles in that state, because its first poll runs after _init returns. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
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
_observeChangesshares oneObserveMultiplexerper cursor, but registers a new one in_observeMultiplexersonly after its driver has started (_selectReactivityDriver, then_init):observeChangescalls for the same cursor that arrive while the first driver starts each create their own multiplexer and driver, and run the first query again. The last one to start keeps the map entry.onStopdeletes the map entry without a check. When an earlier multiplexer stops, it removes the entry of a live one, and later calls start yet another.A related gap:
queryErrorstops the multiplexer but never settles its ready promise, so handles already waiting on it wait for good. The polling driver hits this today, because its first poll runs after_initreturns, when later calls can already share the multiplexer.Changes
mongo_connection.js: the multiplexer is registered before anything yields, andonStopremoves the entry only if it is still this multiplexer. A driver that fails to select, construct or_initgoes toqueryError.observe_multiplex.ts:queryErrorrejects the ready promise, so every waiting handle gets the error. A handle that found the multiplexer before it stopped gets the same error, instead of aTypeErroron the null_handles. A secondqueryErrorfor the same multiplexer only rethrows, because a driver can report its first query's error and then throw it from_init.tests/observe_sharing_tests.js.Verification
The
mongopackage's server tests (test-server-tests-in-console-once), run twice:queryErrortest times out, because the waiting handles never settle.