Skip to content

Fix unit of work middleware edge cases and document its options - #26299

Merged
hikalkan merged 1 commit into
rel-10.7from
maliming/uow-middleware-26259
Oct 16, 2026
Merged

hikalkan merged 1 commit into
rel-10.7from
maliming/uow-middleware-26259

Conversation

@maliming

@maliming maliming commented Oct 16, 2026 •

Copy link
Copy Markdown
Member

Resolve #26259

UseUnitOfWork() completes the request unit of work after the rest of the pipeline. If the action returned a body, the response has already started by then. So when the commit or a unit of work event handler fails, the client still gets 200 OK with the success body, and the data is not saved.

The startup templates will use UseAbpExceptionHandling() instead. Then the MVC action and page filters complete the unit of work before the result is written, and a failure returns an error. The unit of work document now explains this, the middleware options and their limits.

Also fixed:

  • A SignalR hub connection kept one unit of work for its whole lifetime, so writes in hub calls could be lost when it closed. The middleware now skips hub requests. A hub method that queries an IQueryable directly needs its own unit of work.
  • TryBeginReserved no longer reuses a reservation that was already completed or disposed, like one a background task sees after its request ends. Such work now starts a new unit of work.

- Skip SignalR hub requests in `AbpUnitOfWorkMiddleware`
- Don't begin a completed or disposed reservation in `TryBeginReserved`
@codecov

codecov Bot commented Oct 16, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 21.42857% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 49.91%. Comparing base (494a8c8) to head (9496fb8).
⚠️ Report is 6 commits behind head on rel-10.7.

Files with missing lines Patch % Lines
...w/UnitOfWorkMiddleware_Exception_Rollback_Tests.cs 0.00% 6 Missing ⚠️
...Abp/AspNetCore/Mvc/Uow/UnitOfWorkTestController.cs 0.00% 4 Missing ⚠️
...Volo/Abp/AspNetCore/Uow/AbpUnitOfWorkMiddleware.cs 66.66% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##           rel-10.7   #26299      +/-   ##
============================================
+ Coverage     49.89%   49.91%   +0.02%     
============================================
  Files          3857     3857              
  Lines        135140   135153      +13     
  Branches      10243    10244       +1     
============================================
+ Hits          67426    67464      +38     
+ Misses        65701    65659      -42     
- Partials       2013     2030      +17     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@maliming
maliming requested a review from hikalkan October 16, 2026 05:34
@hikalkan
hikalkan merged commit c60f71c into rel-10.7 Oct 16, 2026
4 of 5 checks passed
@hikalkan
hikalkan deleted the maliming/uow-middleware-26259 branch October 16, 2026 05:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants