Repository navigation
test(integration): negative check for the abort scenario (do not merge) - #1272
chappie-daemon wants to merge 1 commit into
Conversation
Throwaway branch: proves the scenario fails without the #1243 fix before it is added to that pull request. Deleted once the evidence is recorded.
|
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: true
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
|
Negative check recorded: the scenario fails on unfixed |
Coverage Report for CI Build 46171924740Coverage decreased (-2.0%) to 78.46%Details
Uncovered ChangesNo uncovered changes found. Coverage Regressions309 previously-covered lines in 38 files lost coverage.
Coverage Stats💛 - Coveralls |
…onnection (#1271) Closes #1243. A cherry-pick of `9f8c1668` from [`AgrimTawani:fix/1243-req-cursor-release`](https://github.com/AgrimTawani/nostream/tree/fix/1243-req-cursor-release), credited to @AgrimTawani, taken with `git cherry-pick -x`. The diff is theirs, unchanged. ## What was wrong A REQ's stored-events read is a knex stream over a pg cursor, and aborting it (CLOSE, a closed socket, a rate-limit refusal) destroyed that stream at once. Two windows make that unsafe: - **Before knex holds a connection**: its close handler throws the `__knexUid` TypeError the worker logs as "Unable to acquire connection", and the connection the pool hands out afterwards runs the query into the closed stream and is never released. - **Before pg has submitted the query** (it queues behind a connection still closing a previous cursor): the cursor close is a no-op, so pg submits it afterwards and the backend sits `active` in `ClientRead` for good while the pool hands the connection to queries that queue behind it. Each abort that lands in one of those windows costs a connection, the windows widen as the pool fills, and once it is full every REQ on the worker hangs. ## What the change does `abortableQueryStream` (`src/utils/query-stream.ts`) is what the caller pipes and aborts. The subscription still ends at once on abort — knex's stream is destroyed only once knex has piped its query in and the cursor is idle, done or errored — and a REQ aborted before its query starts no longer starts one. Peer feeds stay streamed: no buffering is added, so the `peer.subscription.maxLimit: 0` feed keeps its streaming behaviour. ## Evidence from the author - New unit cases fail on the old code and pass on the new. - Against Postgres 16, pool max 4, 600 REQs aborted at random points: the old path leaves the pool full, the new one leaves it empty with every connection usable. - `lint`, `build:check` and the 3601-case unit suite pass on their branch. ## Verification on this branch Run here, in a scratch clone on `a4246b9` with the cherry-pick applied: ``` pnpm run build # tsc, clean pnpm exec mocha test/unit/utils/query-stream.spec.ts \ test/unit/handlers/subscribe-message-handler.spec.ts # 87 passing ``` And the new cases are load-bearing: restoring only `src/handlers/subscribe-message-handler.ts` to `a4246b9` while keeping the new specs turns that run into **2 failing**, so the tests fail on the old code rather than merely passing on the new. `biome lint` on the four touched files reports nothing. The Postgres and full-suite runs above are the author's. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit * **Bug Fixes** * Aborting a subscription request now safely ends its query and releases the connection, helping prevent connections from remaining occupied. * Requests canceled before query startup no longer run a query. * Stream errors and cancellations are handled without prematurely closing the underlying stream, improving reliability during interrupted requests. * Repeatedly opening and closing subscriptions no longer leaves database connections or backend activity lingering. <!-- end of auto-generated comment: release notes by coderabbit.ai --> ## Integration coverage `test/integration/features/subscriptions/req-abort.feature` runs the claim itself against a real Postgres: 25 subscriptions are opened and closed at once, half with the CLOSE in the same tick and half a tick later, then `pool.numUsed() === 0` and no backend is left `active` in `pg_stat_activity`. Proven able to fail before it was added: the same scenario was run against unfixed `main` on a throwaway branch (PR #1272, now closed and deleted) and failed there.
Throwaway: runs the new abort-storm integration scenario against unfixed
mainto show it fails. Closed once the run is recorded.