Conversation
Collaborator
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.
Fix #16524
Summary
The
Collectionconstructor only callsonOpen()ifconn.readyStateis connected. That getter reportsdisconnectedwhen the last heartbeat is stale, even though_readyStatenever changed. A model compiled in that window never gets its collection opened, and since no state transition happens later, the automaticensureIndexes()sits in the collection queue forever andModel.init()never settles.The fix checks
_readyStatein the constructor instead, the same checkuseDb()uses to decide whether it can wire up right away. Buffered connection-level ops (like the_waitForConnect()ininit()) still wait for the heartbeat to recover, as #16203 set up.Examples
Added a test in
test/connection.test.jsthat compiles a model with a unique index while the heartbeat is stale, emits a heartbeat, then checks thatinit()resolves andname_1exists. It times out on master. The repro script from the issue also printssettledand[ '_id_', 'name_1' ]with this change.