Repository navigation
Conversation
Contributor
There was a problem hiding this comment.
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.
This was referenced Oct 18, 2026
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
Fixes #16561.
getDriverCursor()currently waits forever when called after a pre-find hook has failed: the stored initialization error is ignored and thecursorevent will never arrive. Reject with the stored_errorbefore 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:
git diff --check: passed.eachAsynchelper tests: 9 passing, 1 timeout. The samegh-8235test 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.