Skip to content

fix: clean up abort listeners and timers in Query.signal and cursor iterator - #1342

Open
ragib-mrb wants to merge 1 commit into
porsager:masterfrom
ragib-mrb:fix/query-signal-and-cursor-cleanup
Open

ragib-mrb wants to merge 1 commit into
porsager:masterfrom
ragib-mrb:fix/query-signal-and-cursor-cleanup

Conversation

@ragib-mrb

Copy link
Copy Markdown
Contributor

Summary

In src/query.js:

  1. Calling query.signal(signal2) after query.signal(signal1) overwrote this.aborts without invoking the previous cleanup function, leaving the first abort listener attached to signal1 (so aborting signal1 could still cancel the query and the listener was never removed on settlement).
  2. In Query.prototype.cursor(), the async-iterator this.resolve and this.reject overrides omitted this.timer && untime(this), this.aborts && this.aborts(), and (in reject) this.timedOut && x && timedOut(x) && (x = late(this, x)), leaving abort listeners and query-timeout timers uncleaned when a cursor iterator settled.

Fix

  • Call this.aborts && this.aborts() before replacing the signal in Query.prototype.signal().
  • Mirror Query.prototype.resolve and Query.prototype.reject cleanup (untime, aborts, and timedOut -> late) in the cursor() async iterator settlement handlers.
  • Add unit tests in tests/unit/cancel.js.

Testing

  • npm run test:unit (186/186 pass)
  • npm run test:simulate (2000 seeds pass)

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.

1 participant