Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(NODE-6258): add signal support to find and aggregate #4364

Merged
merged 33 commits into from
Jan 27, 2025

Conversation

nbbeeken
Copy link
Contributor

@nbbeeken nbbeeken commented Jan 7, 2025

Description

What is changing?

  • Adds signal support to cursor APIs
    • This now attaches a signal to an operation which is used the following steps:
      • surrounding autoConnect (not interrupting)
      • server selection
      • connection checkout
      • connection r/w
      • connection encrypt/decrypt (kms request and fetchCollectionInfo interrupt)
Is there new documentation needed for these changes?

Yes, API docs.

What is the motivation for this change?

AbortController/AbortSignal has become the defacto interruption mechanism for async operations. We're starting small by linking an abort signal to the lifetime of a cursor so that .next() / toArray() / for-await usage can be interrupted by external means.

Release Highlight

🧪 Experimental AbortSignal support added to Find and Aggregate! 🚥

A signal argument can now be passed to the following APIs:

  • collection.find() & collection.findOne()
  • collection.aggregate() & collection.countDocuments()

In order to support field level encryption properly, also:

  • db.listCollections()
  • db.command()

When aborted, the signal will interrupt the execution of each of each of these APIs. For the cursor-based APIs, this will be observed when attempting to consume from the cursor via toArray(), next(), for-await, etc.

There is a known limitation: aborting a signal closes a perfectly healthy connection which can cause unnecessary connection reestablishment so we're releasing this as experimental for evaluation in use cases that can tolerate the shortcoming.

Double check the following

  • Ran npm run check:lint script
  • Self-review completed using the steps outlined here
  • PR title follows the correct format: type(NODE-xxxx)[!]: description
    • Example: feat(NODE-1234)!: rewriting everything in coffeescript
  • Changes are covered by tests
  • New TODOs have a related JIRA ticket

src/cursor/abstract_cursor.ts Outdated Show resolved Hide resolved
src/utils.ts Show resolved Hide resolved
@nbbeeken nbbeeken force-pushed the NODE-6258-abortsignal branch 2 times, most recently from d1b4562 to 9b76e10 Compare January 14, 2025 20:05
@nbbeeken nbbeeken changed the base branch from main to NODE-6664-fix-test-squash January 14, 2025 20:05
@nbbeeken nbbeeken force-pushed the NODE-6258-abortsignal branch from d18a156 to a2af7ed Compare January 14, 2025 21:09
Base automatically changed from NODE-6664-fix-test-squash to main January 14, 2025 22:11
@nbbeeken nbbeeken force-pushed the NODE-6258-abortsignal branch 7 times, most recently from c05a69d to a68b3cb Compare January 15, 2025 18:30
@nbbeeken nbbeeken marked this pull request as ready for review January 15, 2025 18:32
@nbbeeken nbbeeken force-pushed the NODE-6258-abortsignal branch from a68b3cb to d5ed413 Compare January 15, 2025 20:33
@nbbeeken nbbeeken force-pushed the NODE-6258-abortsignal branch from d5ed413 to ab02d53 Compare January 15, 2025 20:42
src/cmap/connection.ts Outdated Show resolved Hide resolved
test/tools/utils.ts Show resolved Hide resolved
test/integration/node-specific/abort_signal.test.ts Outdated Show resolved Hide resolved
test/integration/node-specific/abort_signal.test.ts Outdated Show resolved Hide resolved
src/mongo_types.ts Outdated Show resolved Hide resolved
src/cmap/connection.ts Outdated Show resolved Hide resolved
src/cursor/find_cursor.ts Show resolved Hide resolved
src/sdam/server.ts Outdated Show resolved Hide resolved
src/cursor/abstract_cursor.ts Show resolved Hide resolved
@baileympearson baileympearson self-assigned this Jan 16, 2025
@baileympearson baileympearson added the Primary Review In Review with primary reviewer, not yet ready for team's eyes label Jan 16, 2025
@nbbeeken nbbeeken requested a review from W-A-James January 24, 2025 17:46
Copy link
Contributor

@baileympearson baileympearson left a comment

Choose a reason for hiding this comment

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

Just some minor clarification

src/utils.ts Outdated Show resolved Hide resolved
src/mongo_types.ts Outdated Show resolved Hide resolved
src/sdam/server.ts Outdated Show resolved Hide resolved
W-A-James
W-A-James previously approved these changes Jan 24, 2025
src/mongo_types.ts Outdated Show resolved Hide resolved
@nbbeeken nbbeeken added Team Review Needs review from team and removed Primary Review In Review with primary reviewer, not yet ready for team's eyes labels Jan 27, 2025
@W-A-James W-A-James merged commit 73def18 into main Jan 27, 2025
26 of 30 checks passed
@W-A-James W-A-James deleted the NODE-6258-abortsignal branch January 27, 2025 16:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Team Review Needs review from team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants