-
Type: Investigation
-
Resolution: Unresolved
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: None
Use Case
As a... Node.js Driver user
I want... to abort in-progress operations
So that... I can stop waiting for and spending resources on a result that will not be used
Avoid load on DB for ignored queries.
Eg when doing a search, if the count operation takes significantly longer (eg 200ms) than finding the results to display, we can cancel it instead of just ignoring it.
Or when a client cancels their http request, we can cancel ongoing mongodb read queries for that request
User Experience
- What is the desired/expected outcome for the user once this ticket is implemented?
Being able to pass a signal parameter to queries, which would be from an AbortController.
Triggering:
const abort = new AbortController(); const query = db.coll("...").countDocuments(..., \{ signal: abort.signal}); abort.abort();
Dependencies
- AbortController & AbortSignal
Risks/Unknowns
- What could go wrong while implementing this change? (e.g., performance, inadvertent behavioral changes in adjacent functionality, existing tech debt, etc)
- Care must be taken to add and remove AbortSignal listeners to avoid memory leaks
- Signal code should be written in a way that makes it no-op when a signal is not provided (optional chaining etc) for performance
- Is there an opportunity for better cross-driver alignment or testing in this area?
- No
- Is there an opportunity to improve existing documentation on this subject?
- Not existing, we should document how signals can be used with the APIs we add support to
Acceptance Criteria
Implementation Requirements
- Add AbortSignal support to the TBD APIs
- (list here)
- Ensure signal interrupts a query during any point in its lifecycle:
- Server Selection
- Connection Checkout
- (if enabled) Client Side Encryption
- R/W Socket
Testing Requirements
- Check various signal states, already aborted, aborted while the driver is in one of the lifecycle states listed above, aborted after.
- For cursor operations check abort works as expected in between commands (ex. before/after find and getMores accordingly)
Documentation Requirements
- Add API documentation to the signal option
Follow Up Requirements
- depends on
-
NODE-6258 Cancel individual queries with AbortController
- Closed