Fix NRE in batch state checker on fresh ExecutionContext#25367
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes an AsyncLocal initialization bug in ABP’s batch state checkers so fresh ExecutionContexts can rebuild feature/permission-based state without hitting a NullReferenceException. It updates the core batch checker accessors and adds regression coverage around permission-definition cache rebuilds and fresh-context access.
Changes:
- Changed
RequireFeaturesSimpleBatchStateChecker<TState>.CurrentandRequirePermissionsSimpleBatchStateChecker<TState>.Currentto lazily initialize per execution context. - Added regression tests for accessing
Currentfrom a freshExecutionContextand for rebuilding static permission definitions after cache clears. - Updated authorization test setup to include the features module and a feature-gated permission definition provider.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
framework/src/Volo.Abp.Features/Volo/Abp/Features/RequireFeaturesSimpleBatchStateChecker.cs |
Switches feature batch checker Current from static-constructor init to lazy AsyncLocal init. |
framework/src/Volo.Abp.Authorization/Volo/Abp/Authorization/Permissions/RequirePermissionsSimpleBatchStateChecker.cs |
Applies the same lazy AsyncLocal initialization to permission batch checkers. |
framework/test/Volo.Abp.Features.Tests/Volo/Abp/Features/RequireFeaturesSimpleBatchStateChecker_Tests.cs |
Adds a fresh-ExecutionContext regression test for feature batch checker access. |
framework/test/Volo.Abp.Authorization.Tests/Volo/Abp/Authorization/RequirePermissionsSimpleBatchStateChecker_Tests.cs |
Adds the matching fresh-ExecutionContext regression test for permission batch checker access. |
framework/test/Volo.Abp.Authorization.Tests/Volo/Abp/Authorization/TestServices/FeatureGatedTestPermissionDefinitionProvider.cs |
Introduces a permission definition that exercises RequireFeatures(...) during permission-store rebuilds. |
framework/test/Volo.Abp.Authorization.Tests/Volo/Abp/Authorization/StaticPermissionDefinitionStore_Tests.cs |
Adds a cache-clear/rebuild regression test for permission definitions on a fresh execution context. |
framework/test/Volo.Abp.Authorization.Tests/Volo/Abp/Authorization/Authorization_Tests.cs |
Relaxes group-count expectations to allow the extra test permission group. |
framework/test/Volo.Abp.Authorization.Tests/Volo/Abp/Authorization/AbpAuthorizationTestModule.cs |
Adds AbpFeaturesModule to the authorization test module dependencies. |
framework/test/Volo.Abp.Authorization.Tests/Volo.Abp.Authorization.Tests.csproj |
Adds the features project reference needed by the new authorization regression tests. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## rel-10.3 #25367 +/- ##
============================================
+ Coverage 49.30% 49.78% +0.48%
============================================
Files 3667 3609 -58
Lines 123171 120714 -2457
Branches 9407 9220 -187
============================================
- Hits 60731 60099 -632
+ Misses 60631 58818 -1813
+ Partials 1809 1797 -12 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
salihozkara
approved these changes
May 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
RequireFeaturesSimpleBatchStateChecker<TState>.CurrentandRequirePermissionsSimpleBatchStateChecker<TState>.Currentinitialize theirAsyncLocal<>value from a static type initializer, so the value is only visible on the ExecutionContext that triggered it. Any other ExecutionContext (a new HTTP request, queued event handler,Task.Runwithout flow) seesnulland crashesAddCheckModels(...)with NRE — reproducible byawait _distributedEventBus.PublishAsync(new StaticPermissionDefinitionChangedEvent()), which clears the static permission caches and forces the next request to rebuild definitions on a fresh ExecutionContext through a provider that usesRequireFeatures(...)(e.g.AbpAuditLoggingPermissionDefinitionProvider).Lazy-init
Currentper ExecutionContext.