Skip to content

fix(cursor): reject getDriverCursor after initialization errors - #16563

Merged
vkarpov15 merged 1 commit into
Automattic:masterfrom
IbrahimHafez1:codex/query-cursor-initialization-error
Oct 7, 2026
Merged

vkarpov15 merged 1 commit into
Automattic:masterfrom
IbrahimHafez1:codex/query-cursor-initialization-error

Conversation

@IbrahimHafez1

Copy link
Copy Markdown
Contributor

Summary

Fixes #16561.

getDriverCursor() currently waits forever when called after a pre-find hook has failed: the stored initialization error is ignored and the cursor event will never arrive. Reject with the stored _error before registering the event wait.

The existing driver-cursor fast path and pending-initialization behavior are preserved. This adds only a constant-time check when no driver cursor is available, with no timers, extra listeners, or database operations. Skipped middleware behavior is outside this change.

Examples

The regression tests use a real rejecting pre-find hook and call getDriverCursor() both before and after its error event. On unchanged master, the early call rejects correctly and the late call times out. Both reject with the original error after this fix.

Validation on Node.js 22.17.1 / MongoDB 8.2.3:

  • Query-cursor and aggregation suites: 136 passing.
  • ESLint on the changed source and test: passed.
  • git diff --check: passed.
  • Broader eachAsync helper tests: 9 passing, 1 timeout. The same gh-8235 test times out on the unchanged checkout; its source and helper are identical to master. That test runs 1,001 sequential zero-delay timers under a 10-second limit on this Windows host. No test timeout or unrelated implementation was changed.

Developed with AI assistance; the reproduction, patch, and tests were checked against current master.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The targeted guard preserves existing paths and the regression tests cover both timing cases.

Review effort: Balanced
Findings: None

What changed in this PR

Fixes getDriverCursor() hanging after query cursor initialization errors.

Changes:

  • Rejects immediately with the stored initialization error.
  • Adds regression coverage for calls before and after error emission.
File Description
lib/​cursor/​queryCursor.js Handles stored initialization errors.
test/​query.cursor.test.js Tests both error timing scenarios.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@vkarpov15 vkarpov15 added this to the 9.11.1 milestone Oct 7, 2026
@vkarpov15
vkarpov15 merged commit 171e39b into Automattic:master Oct 7, 2026
32 checks passed
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.

getDriverCursor() never settles when called after a pre-find error

3 participants