Skip to content

test(integration): negative check for the abort scenario (do not merge) - #1272

Closed
chappie-daemon wants to merge 1 commit into
mainfrom
verify/1243-scenario-can-fail
Closed

chappie-daemon wants to merge 1 commit into
mainfrom
verify/1243-scenario-can-fail

Conversation

@chappie-daemon

Copy link
Copy Markdown
Collaborator

Throwaway: runs the new abort-storm integration scenario against unfixed main to show it fails. Closed once the run is recorded.

Throwaway branch: proves the scenario fails without the #1243 fix before it is
added to that pull request. Deleted once the evidence is recorded.
@changeset-bot

changeset-bot Bot commented Nov 28, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 3d7888f

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai

coderabbitai Bot commented Nov 28, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Share

@chappie-daemon

Copy link
Copy Markdown
Collaborator Author

Negative check recorded: the scenario fails on unfixed main — numUsed() === 2 against an expected 0, then the second step times out on a pool that has no connection left to give. Closing and deleting the branch.

@coveralls

Copy link
Copy Markdown
Collaborator

Coverage Report for CI Build 46171924740

Coverage decreased (-2.0%) to 78.46%

Details

  • Coverage decreased (-2.0%) from the base build.
  • Patch coverage: No coverable lines changed in this PR.
  • 309 coverage regressions across 38 files.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

309 previously-covered lines in 38 files lost coverage.

Top 10 Files by Coverage Loss Lines Losing Coverage Coverage
src/utils/relay-probe/ws-protocol-probe.ts 101 11.15%
src/scripts/export-events.ts 30 67.53%
src/controllers/admission/get-admission-check-controller.ts 20 9.62%
src/import-events.ts 16 64.82%
src/utils/admin-health.ts 14 50.91%
src/factories/web-app-factory.ts 11 57.69%
src/controllers/invoices/get-invoice-status-controller.ts 10 12.0%
src/handlers/request-handlers/rate-limiter-middleware.ts 9 17.5%
src/repositories/event-repository.ts 8 94.13%
src/factories/rate-limiter-factory.ts 7 33.33%

Coverage Stats

Coverage Status
Relevant Lines: 15204
Covered Lines: 12420
Line Coverage: 81.69%
Relevant Branches: 8459
Covered Branches: 6146
Branch Coverage: 72.66%
Branches in Coverage %: Yes
Coverage Strength: 691.36 hits per line

💛 - Coveralls

chappie-daemon added a commit that referenced this pull request Nov 28, 2026
…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.
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.

2 participants