Skip to content

fix(sql-mssql): keep interrupted requests leased until Tedious settles them - #9636

Merged
tim-smart merged 4 commits into
v4/next-minorfrom
agent/nelson/c1d55c9e5b7b
Oct 20, 2026
Merged

tim-smart merged 4 commits into
v4/next-minorfrom
agent/nelson/c1d55c9e5b7b

Conversation

@tim-smart

Copy link
Copy Markdown
Contributor

Interrupting an MSSQL query released its connection back to the pool as soon as conn.cancel() returned. Tedious is still in SentClientRequest at that point and only goes back to LoggedIn once the server acknowledges the attention. So the next borrower failed with EINVALIDSTATE: Requests can only be made in the LoggedIn state, not the SentClientRequest state. This is the intermittent failure in the PersistedQueue SQL claims tests: a lock-refresh UPDATE interrupted at scope shutdown left its connection busy for the next test's migration query.

Queries and stored procedures now go through one helper. On interruption it cancels the request and waits for the Tedious request callback before the cleanup finishes, so the lease is held until the connection is idle. Tedious calls that callback on every terminal path: normal completion, cancel acknowledgement (ECANCEL), cancel timeout (socket error, connection goes to Final) and close (ECLOSE). A cancel that never gets acknowledged is therefore bounded by cancelTimeout, and the ended connection is discarded by the existing acquireConnection latch. The conn.cancel() before each execSql/callProcedure is removed. It was a no-op on an idle connection and couldn't drain a busy one.

Transactions are covered as well. begin/commit/rollback already run uninterruptibly, and an interrupted statement inside withTransaction now settles before ROLLBACK runs. Before this change the ROLLBACK itself failed with EINVALIDSTATE and became a defect, which left an open transaction on a pooled connection.

Commits

  • test(sql-mssql): reproduce busy connection reuse after interruption is the tests-only regression from test(sql-mssql): reproduce connection reuse before cancellation completes #9630, cherry-picked unchanged onto the current v4/next-minor.
  • fix(sql-mssql): ... contains the runtime change. It also updates the Tedious mock in Client.test.ts so cancel() and close() call the pending request back the way Tedious does. The old mock dropped the request silently. The cancel-timeout test now checks that interruption waits for the connection to end.

Validation (local, real SQL Server 2022 via testcontainers)

  • Cancellation.integration.test.ts fails with EINVALIDSTATE without the fix and passes with it, on Node and on Bun 1.3.13 (CI pins 1.4.0).
  • Client.test.ts: 22/22 on Node (5 repeated runs) and on Bun.
  • Persistence.integration.test.ts: 35/35 on Node. On Bun, the 3 PersistedQueue SQL claims tests pass.
  • Throwaway real-server checks, not committed: an interrupted statement inside withTransaction rolls back cleanly (no rows, @@TRANCOUNT 0, no defect), an interrupted stored procedure leaves the connection reusable, and 25 interrupt/query cycles on a one-connection pool succeed. All three fail without the fix.
  • pnpm lint-fix and pnpm check pass.

KeyValueStore.integration.test.ts and SqlEventLogServerEncrypted.integration.test.ts were not validated locally. The shared host was overloaded (load around 20 on 8 cores) and their container setup hooks timed out before any test ran. The full Bun run of Persistence.integration.test.ts hit the same container-start timeout outside the claims block. CI will cover these.

Closes EFF-2604

@changeset-bot

changeset-bot Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 62e05af

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 33 packages
Name Type
@effect/sql-mssql Patch
effect Patch
@effect/opentelemetry Patch
@effect/vitest Patch
@effect/ai-anthropic Patch
@effect/ai-cloudflare Patch
@effect/ai-openai-compat Patch
@effect/ai-openai Patch
@effect/ai-openrouter Patch
@effect/ai-typesafe Patch
@effect/atom-react Patch
@effect/atom-solid Patch
@effect/atom-vue Patch
@effect/platform-browser Patch
@effect/platform-bun Patch
@effect/platform-deno Patch
@effect/platform-node-shared Patch
@effect/platform-node Patch
@effect/sql-clickhouse Patch
@effect/sql-d1 Patch
@effect/sql-libsql Patch
@effect/sql-mysql2 Patch
@effect/sql-pg Patch
@effect/sql-pglite Patch
@effect/sql-sqlite-bun Patch
@effect/sql-sqlite-do Patch
@effect/sql-sqlite-node Patch
@effect/sql-sqlite-react-native Patch
@effect/sql-sqlite-wasm Patch
@effect/docgen Patch
@effect/doctest Patch
@effect/graphql-generator Patch
@effect/openapi-generator Patch

Not sure what this means? Click here to learn what changesets are.

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

@effect-bot
effect-bot force-pushed the v4/next-minor branch 3 times, most recently from 467e08d to 616dac1 Compare October 20, 2026 22:44
@tim-smart
tim-smart force-pushed the agent/nelson/c1d55c9e5b7b branch from 992fbbc to 48ef9e6 Compare October 20, 2026 23:00
@tim-smart
tim-smart enabled auto-merge (squash) October 20, 2026 23:02
@tim-smart
tim-smart disabled auto-merge October 20, 2026 23:04
@github-actions

Copy link
Copy Markdown
Contributor

Bundle Size Analysis

Generated from PR build output; treat the content below as untrusted.

File Name Current Size Previous Size Difference
arbitrary-combinators.ts 39.16 KB 39.16 KB 0.00 KB (0.00%)
basic.ts 7.07 KB 7.07 KB 0.00 KB (0.00%)
batching.ts 10.93 KB 10.93 KB 0.00 KB (0.00%)
brand.ts 6.71 KB 6.71 KB 0.00 KB (0.00%)
cache.ts 11.37 KB 11.37 KB 0.00 KB (0.00%)
config.ts 22.53 KB 22.53 KB 0.00 KB (0.00%)
differ.ts 21.68 KB 21.68 KB 0.00 KB (0.00%)
http-client.ts 24.59 KB 24.59 KB 0.00 KB (0.00%)
http-router.ts 35.72 KB 35.72 KB 0.00 KB (0.00%)
logger.ts 11.71 KB 11.71 KB 0.00 KB (0.00%)
metric.ts 9.30 KB 9.30 KB 0.00 KB (0.00%)
optic.ts 6.93 KB 6.93 KB 0.00 KB (0.00%)
pubsub.ts 15.81 KB 15.81 KB 0.00 KB (0.00%)
queue.ts 12.63 KB 12.63 KB 0.00 KB (0.00%)
schedule.ts 11.61 KB 11.61 KB 0.00 KB (0.00%)
schema-bigdecimal.ts 13.87 KB 13.87 KB 0.00 KB (0.00%)
schema-binary.ts 40.55 KB 40.55 KB 0.00 KB (0.00%)
schema-class.ts 21.39 KB 21.39 KB 0.00 KB (0.00%)
schema-fromJsonSchemaDocument.ts 32.35 KB 32.35 KB 0.00 KB (0.00%)
schema-representation-roundtrip.ts 27.55 KB 27.55 KB 0.00 KB (0.00%)
schema-string-transformation.ts 15.11 KB 15.11 KB 0.00 KB (0.00%)
schema-string.ts 12.13 KB 12.13 KB 0.00 KB (0.00%)
schema-template-literal.ts 16.05 KB 16.05 KB 0.00 KB (0.00%)
schema-toArbitrary.ts 38.68 KB 38.68 KB 0.00 KB (0.00%)
schema-toCodeDocument.ts 25.73 KB 25.73 KB 0.00 KB (0.00%)
schema-toCodecJson.ts 20.61 KB 20.61 KB 0.00 KB (0.00%)
schema-toEquivalence.ts 20.80 KB 20.80 KB 0.00 KB (0.00%)
schema-toFormatter.ts 20.90 KB 20.90 KB 0.00 KB (0.00%)
schema-toJsonSchemaDocument.ts 25.54 KB 25.54 KB 0.00 KB (0.00%)
schema-toRepresentation.ts 20.90 KB 20.90 KB 0.00 KB (0.00%)
schema.ts 20.57 KB 20.57 KB 0.00 KB (0.00%)
stm.ts 13.91 KB 13.91 KB 0.00 KB (0.00%)
stream.ts 10.16 KB 10.16 KB 0.00 KB (0.00%)

@effect-bot
effect-bot force-pushed the v4/next-minor branch 2 times, most recently from 2988dfb to 3d6518f Compare October 20, 2026 23:19
@effect-bot
effect-bot force-pushed the agent/nelson/c1d55c9e5b7b branch from 48ef9e6 to 62e05af Compare October 20, 2026 23:20
@tim-smart
tim-smart enabled auto-merge (squash) October 20, 2026 23:23
@tim-smart
tim-smart merged commit 8e2bcca into v4/next-minor Oct 20, 2026
9 checks passed
@tim-smart
tim-smart deleted the agent/nelson/c1d55c9e5b7b branch October 20, 2026 23:29
@effect-bot effect-bot mentioned this pull request Oct 20, 2026
effect-bot added a commit that referenced this pull request Oct 21, 2026
…s them (#9636)

Co-authored-by: Effect Bot <tech-ops@effectful.co>
tim-smart added a commit that referenced this pull request Oct 21, 2026
…s them (#9636)

Co-authored-by: Effect Bot <tech-ops@effectful.co>
effect-bot added a commit to devangpratap/effect that referenced this pull request Oct 21, 2026
…s them (Effect-TS#9636)

Co-authored-by: Effect Bot <tech-ops@effectful.co>
tim-smart added a commit that referenced this pull request Oct 21, 2026
…s them (#9636)

Co-authored-by: Effect Bot <tech-ops@effectful.co>
effect-bot added a commit that referenced this pull request Oct 21, 2026
…s them (#9636)

Co-authored-by: Effect Bot <tech-ops@effectful.co>
effect-bot added a commit to lloydrichards/open_effect that referenced this pull request Oct 21, 2026
…s them (Effect-TS#9636)

Co-authored-by: Effect Bot <tech-ops@effectful.co>
effect-bot added a commit that referenced this pull request Oct 21, 2026
…s them (#9636)

Co-authored-by: Effect Bot <tech-ops@effectful.co>
effect-bot added a commit to lloydrichards/open_effect that referenced this pull request Oct 21, 2026
…s them (Effect-TS#9636)

Co-authored-by: Effect Bot <tech-ops@effectful.co>
effect-bot added a commit that referenced this pull request Oct 22, 2026
…s them (#9636)

Co-authored-by: Effect Bot <tech-ops@effectful.co>
effect-bot added a commit that referenced this pull request Oct 22, 2026
…s them (#9636)

Co-authored-by: Effect Bot <tech-ops@effectful.co>
effect-bot added a commit that referenced this pull request Oct 22, 2026
…s them (#9636)

Co-authored-by: Effect Bot <tech-ops@effectful.co>
effect-bot added a commit that referenced this pull request Oct 22, 2026
…s them (#9636)

Co-authored-by: Effect Bot <tech-ops@effectful.co>
effect-bot added a commit that referenced this pull request Oct 22, 2026
…s them (#9636)

Co-authored-by: Effect Bot <tech-ops@effectful.co>
effect-bot added a commit that referenced this pull request Oct 22, 2026
…s them (#9636)

Co-authored-by: Effect Bot <tech-ops@effectful.co>
tim-smart added a commit that referenced this pull request Oct 22, 2026
…s them (#9636)

Co-authored-by: Effect Bot <tech-ops@effectful.co>
effect-bot added a commit that referenced this pull request Oct 22, 2026
…s them (#9636)

Co-authored-by: Effect Bot <tech-ops@effectful.co>
effect-bot added a commit that referenced this pull request Oct 22, 2026
…s them (#9636)

Co-authored-by: Effect Bot <tech-ops@effectful.co>
effect-bot added a commit that referenced this pull request Oct 22, 2026
…s them (#9636)

Co-authored-by: Effect Bot <tech-ops@effectful.co>
effect-bot added a commit that referenced this pull request Oct 22, 2026
…s them (#9636)

Co-authored-by: Effect Bot <tech-ops@effectful.co>
effect-bot added a commit that referenced this pull request Oct 22, 2026
…s them (#9636)

Co-authored-by: Effect Bot <tech-ops@effectful.co>
tim-smart added a commit that referenced this pull request Oct 22, 2026
…s them (#9636)

Co-authored-by: Effect Bot <tech-ops@effectful.co>
effect-bot added a commit that referenced this pull request Oct 22, 2026
…s them (#9636)

Co-authored-by: Effect Bot <tech-ops@effectful.co>
effect-bot added a commit that referenced this pull request Oct 22, 2026
…s them (#9636)

Co-authored-by: Effect Bot <tech-ops@effectful.co>
effect-bot added a commit that referenced this pull request Oct 22, 2026
…s them (#9636)

Co-authored-by: Effect Bot <tech-ops@effectful.co>
effect-bot added a commit that referenced this pull request Oct 22, 2026
…s them (#9636)

Co-authored-by: Effect Bot <tech-ops@effectful.co>
effect-bot added a commit that referenced this pull request Oct 22, 2026
…s them (#9636)

Co-authored-by: Effect Bot <tech-ops@effectful.co>
effect-bot added a commit that referenced this pull request Oct 22, 2026
…s them (#9636)

Co-authored-by: Effect Bot <tech-ops@effectful.co>
tim-smart added a commit that referenced this pull request Oct 22, 2026
…s them (#9636)

Co-authored-by: Effect Bot <tech-ops@effectful.co>
effect-bot added a commit that referenced this pull request Oct 22, 2026
…s them (#9636)

Co-authored-by: Effect Bot <tech-ops@effectful.co>
effect-bot added a commit that referenced this pull request Oct 22, 2026
…s them (#9636)

Co-authored-by: Effect Bot <tech-ops@effectful.co>
effect-bot added a commit that referenced this pull request Oct 22, 2026
…s them (#9636)

Co-authored-by: Effect Bot <tech-ops@effectful.co>
effect-bot added a commit that referenced this pull request Oct 22, 2026
…s them (#9636)

Co-authored-by: Effect Bot <tech-ops@effectful.co>
effect-bot added a commit that referenced this pull request Oct 22, 2026
…s them (#9636)

Co-authored-by: Effect Bot <tech-ops@effectful.co>
effect-bot added a commit that referenced this pull request Oct 22, 2026
…s them (#9636)

Co-authored-by: Effect Bot <tech-ops@effectful.co>
effect-bot added a commit that referenced this pull request Oct 22, 2026
…s them (#9636)

Co-authored-by: Effect Bot <tech-ops@effectful.co>
effect-bot added a commit that referenced this pull request Oct 22, 2026
…s them (#9636)

Co-authored-by: Effect Bot <tech-ops@effectful.co>
effect-bot added a commit that referenced this pull request Oct 22, 2026
…s them (#9636)

Co-authored-by: Effect Bot <tech-ops@effectful.co>
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