Skip to content

Throw StreamLockedException from a batched FetchForExclusiveWriting on a locked stream - #5818

Merged
jeremydmiller merged 3 commits into
JasperFx:masterfrom
esond:batched-exclusive-fetch-stream-locked
Nov 5, 2026
Merged

jeremydmiller merged 3 commits into
JasperFx:masterfrom
esond:batched-exclusive-fetch-stream-locked

Conversation

@esond

@esond esond commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #5817.

A batched FetchForExclusiveWriting on a locked stream now throws StreamLockedException, like the direct call does. Before, it threw MartenCommandException, or NpgsqlException when it wasn't the batch's first item.

Start with BatchedQuery.Execute. It translates a read timeout or 25P02 only while the reader moves into an exclusive fetch's results, because the for update is that item's first statement. The four fetch-plan handlers just report their stream id through a new internal IExclusiveFetchHandler.

  • A slow query elsewhere in the batch still throws MartenCommandException, and a test covers it.
  • Wrapped exceptions such as SessionTransactionUnusableException pass through unchanged.
  • The new tests fail 4 of 5 on the first commit and pass on the second, on net9.0 and net10.0. The FetchForWriting and batched_querying tests also pass.

esond added 2 commits November 4, 2026 22:28
…stream

The non-batched FetchForExclusiveWriting reports a stream another session holds
locked as StreamLockedException. The batched form fails with the timed-out
batch's MartenCommandException instead, or with a bare NpgsqlException when the
exclusive fetch is not the batch's first item. A slow query elsewhere in the
batch has to keep failing as a MartenCommandException.
…n a locked stream

The non-batched FetchForExclusiveWriting turns a read timeout (or 25P02) on the
stream's `for update` into StreamLockedException, but the batched form surfaced
the raw MartenCommandException, or a bare NpgsqlException when the exclusive
fetch was not the batch's first item. A Wolverine handler using
[WriteAggregate(LoadStyle = ConcurrencyStyle.Exclusive)] loads through the
batch, so error handling keyed on StreamLockedException never matched.

BatchedQuery.Execute now applies the same translation, but only when the
failure happens while the reader advances into an exclusive fetch's results,
where its `for update` is the first statement. A slow query elsewhere in the
batch still fails as before.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-05T05:06:51.774800Z 3b004cf New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@jeremydmiller
jeremydmiller merged commit a6c3e77 into JasperFx:master Nov 5, 2026
This was referenced Nov 6, 2026
@esond
esond deleted the batched-exclusive-fetch-stream-locked branch November 20, 2026 17:43
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.

Batched FetchForExclusiveWriting on a locked stream throws MartenCommandException instead of StreamLockedException

2 participants