Skip to content

Fix intermittent NRE in ServerSettings.Create due to config injection race#3419

Merged
Aaronontheweb merged 1 commit intoakkadotnet:devfrom
Aaronontheweb:fix/hosting-http-config-race
Mar 18, 2026
Merged

Fix intermittent NRE in ServerSettings.Create due to config injection race#3419
Aaronontheweb merged 1 commit intoakkadotnet:devfrom
Aaronontheweb:fix/hosting-http-config-race

Conversation

@Aaronontheweb
Copy link
Copy Markdown
Member

Summary

Fixes an intermittent NullReferenceException in ServerSettings.Create() that occurs on Windows CI when akka.http.server config is not yet visible due to a race condition in Akka.NET core's Settings.RebuildConfig().

Root cause: Settings.InjectTopLevelFallback uses CAS for the _fallbackConfig atomic reference but RebuildConfig() writes to the Config property (a plain auto-property) non-atomically. When two threads call InjectTopLevelFallback concurrently, one can overwrite Config with 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 in RebuildConfig remains.

Impact: When the HttpExt extension injects akka.http config via InjectTopLevelFallback and another extension does the same concurrently, ServerSettings.Create() can read a Config snapshot that's missing akka.http.server, causing GetConfig() to return null and 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-inject Akka.Http.Http.DefaultConfig() at builder time in both WithAkkaManagement overloads, so the config is part of the initial ActorSystem config before any concurrent threads can interfere
  • ServerSettings.cs: Add a defensive null guard — if GetConfig("akka.http.server") returns null, re-inject the default config and retry before throwing a descriptive exception

Related

Test plan

  • Existing Akka.Management.Tests.HostingSpecs tests pass (these are the tests that were flaking)
  • Both projects compile cleanly

…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().
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.

1 participant