Skip to content

fix(collection): open collections created while heartbeat is stale - #16525

Closed
lazerg wants to merge 1 commit into
Automattic:masterfrom
lazerg:fix/issue-16524-stale-collection-open
Closed

lazerg wants to merge 1 commit into
Automattic:masterfrom
lazerg:fix/issue-16524-stale-collection-open

Conversation

@lazerg

@lazerg lazerg commented Sep 24, 2026

Copy link
Copy Markdown
Contributor

Fix #16524

Summary

The Collection constructor only calls onOpen() if conn.readyState is connected. That getter reports disconnected when the last heartbeat is stale, even though _readyState never changed. A model compiled in that window never gets its collection opened, and since no state transition happens later, the automatic ensureIndexes() sits in the collection queue forever and Model.init() never settles.

The fix checks _readyState in the constructor instead, the same check useDb() uses to decide whether it can wire up right away. Buffered connection-level ops (like the _waitForConnect() in init()) still wait for the heartbeat to recover, as #16203 set up.

Examples

Added a test in test/connection.test.js that compiles a model with a unique index while the heartbeat is stale, emits a heartbeat, then checks that init() resolves and name_1 exists. It times out on master. The repro script from the issue also prints settled and [ '_id_', 'name_1' ] with this change.

@vkarpov15

Copy link
Copy Markdown
Collaborator

@lazerg can you please take a look at #16527?

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.

Model compiled while readyState reports a stale heartbeat never initializes: Model.init() stays pending and autoIndex never runs (9.10.2)

2 participants