Fix intermittent NRE in ServerSettings.Create due to config injection race#3419
Merged
Aaronontheweb merged 1 commit intoakkadotnet:devfrom Mar 18, 2026
Merged
Conversation
…llback race Pre-inject Akka.Http default config at builder time in WithAkkaManagement hosting extensions so it's part of the initial ActorSystem config, avoiding a race in Settings.RebuildConfig() where concurrent InjectTopLevelFallback calls can overwrite Config with a stale value. Also add a defensive null guard with re-injection retry in ServerSettings.Create().
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.
Summary
Fixes an intermittent
NullReferenceExceptioninServerSettings.Create()that occurs on Windows CI whenakka.http.serverconfig is not yet visible due to a race condition in Akka.NET core'sSettings.RebuildConfig().Root cause:
Settings.InjectTopLevelFallbackuses CAS for the_fallbackConfigatomic reference butRebuildConfig()writes to theConfigproperty (a plain auto-property) non-atomically. When two threads callInjectTopLevelFallbackconcurrently, one can overwriteConfigwith a stale value that's missing the other's injected config. This was partially fixed in akkadotnet/akka.net#7721 (1.5.45) but the stale-write race inRebuildConfigremains.Impact: When the
HttpExtextension injectsakka.httpconfig viaInjectTopLevelFallbackand another extension does the same concurrently,ServerSettings.Create()can read aConfigsnapshot that's missingakka.http.server, causingGetConfig()to returnnulland the next line to throw NRE.Observed on: Windows CI only (PR #3418), due to thread pool scheduling and timer resolution differences. The lease conflict fix in #3418 is unrelated — this is a pre-existing issue.
Changes
AkkaHostingExtensions.cs: Pre-injectAkka.Http.Http.DefaultConfig()at builder time in bothWithAkkaManagementoverloads, so the config is part of the initialActorSystemconfig before any concurrent threads can interfereServerSettings.cs: Add a defensive null guard — ifGetConfig("akka.http.server")returns null, re-inject the default config and retry before throwing a descriptive exceptionRelated
Test plan
Akka.Management.Tests.HostingSpecstests pass (these are the tests that were flaking)