fix(connection): propagate changes to _lastHeartbeatAt to useDb() child connections
#15640
+20
−1
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 #15635
Summary
useDb()child connections have their own_lastHeartbeatAtproperty, but that property is not updated when the client receives aserverHeartbeatSucceededevent. The Connection class only updates the top-level connection's_lastHeartbeatAt. That meansuseDb()child connections' helpers that rely on_waitForConnect(), likedropDatabase(), will hang afterheartbeatFrequencyMS * 2.I didn't register a separate event listener for each
useDb()child connection because of memory leak concerns. With this approach, we don't have to clean up the event listener. Also, this pattern of looping overotherDbsrespects thenoListeneroption.One potential issue: as implemented,
noListenermeans the child connection isn't added to the parent db'sotherDbslist, meaning this fix won't work ifnoListeneris set. However, as implemented, thenoListeneroption doesn't work anyway. SettingnoListenerthrows aMongoParseError: option nolistener is not supportederror because Mongoose doesn't strip that option out before passing it to MongoDB. So I think the answer here is to just remove the noListener option for mongoose 9.Examples