Repository navigation
fix: allow executing a request again after it was canceled - #1790
Conversation
`Request.canceled` was only ever reset in the constructor. Once a request was canceled, every later execution of it failed with `ECANCEL` before being sent. That broke prepared statements for good after one canceled execution, including their unpreparing. The flag is now reset when an execution completes, before the completion callback and events run, so the request can also be executed again from within them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HGJsu1u44CHnt4nkkQ5ias
ReviewLooked through the diff, the surrounding Correctness: looks right. The root cause is accurately diagnosed —
Test coverage: The two new integration tests are good end-to-end reproductions of the reported bug (plain request retry + the prepared-statement leak scenario, including confirming Minor/non-blocking edge case: Overall a well-scoped, well-tested fix with a clear explanation of the ordering rationale in the code comment. No security or performance concerns — this only touches a boolean flag's lifecycle. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1790 +/- ##
==========================================
+ Coverage 81.48% 82.50% +1.01%
==========================================
Files 95 95
Lines 4862 4863 +1
Branches 913 913
==========================================
+ Hits 3962 4012 +50
+ Misses 631 575 -56
- Partials 269 276 +7 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HGJsu1u44CHnt4nkkQ5ias
|
🎉 This PR is included in version 20.3.2 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Master now contains the push parser (#1794) that this branch was built on, and the fixes for output parameters of prepared statements (#1789) and for executing a request again after it was canceled (#1790), which this branch had earlier versions of. The branch's versions of the parser files are kept (they extend the merged parser), with the `process.nextTick` fix from #1794. `Request.callback` only resets `canceled` before calling back, like on master: resetting it afterwards would also clear the cancellation of an execution that was started from the callback. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HGJsu1u44CHnt4nkkQ5ias
Request.canceledis only ever set back tofalsein the constructor. Once a request has been canceled,makeRequestrejects every later execution of it withECANCELbefore sending anything.For a plain request this means it can't be retried after a cancel. For a prepared statement it's worse: a single canceled
execute()makes every laterexecute()fail, andunprepare()fails too, so the statement leaks on the server.Changes
Request.canceledis reset when an execution completes.prepared/error/requestCompletedevents run. So the common pattern of running a request again from its own callback works too.cancel()still affects only the execution in progress, or the next one if it's called before executing. That is unchanged.Tests
New integration tests:
test/integration/connection-test.ts)test/integration/prepare-execute-statements-test.ts)Both fail on master with an uncaught
Canceled.error when the request runs again.Checks
npm run lint(eslint andtsc)npm run buildInitiate Connect Test, which also fails on master in the local test environment.🤖 Generated with Claude Code
https://claude.ai/code/session_01HGJsu1u44CHnt4nkkQ5ias
Generated by Claude Code