-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix Settings.InjectTopLevelFallback
race condition
#7721
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ | |
using Akka.Dispatch; | ||
using Akka.Event; | ||
using Akka.Routing; | ||
using Akka.Util; | ||
using ConfigurationFactory = Akka.Configuration.ConfigurationFactory; | ||
|
||
namespace Akka.Actor | ||
|
@@ -27,7 +28,7 @@ public class Settings | |
{ | ||
private readonly Config _userConfig; | ||
//internal static readonly Config AkkaDllConfig = ConfigurationFactory.FromResource<Settings>("Akka.Configuration.Pigeon.conf"); | ||
private Config _fallbackConfig; | ||
private readonly AtomicReference<Config> _fallbackConfig; | ||
|
||
private void RebuildConfig() | ||
{ | ||
|
@@ -42,13 +43,20 @@ private void RebuildConfig() | |
/// <summary> | ||
/// Injects a system config at the top of the fallback chain | ||
/// </summary> | ||
/// <param name="config">TBD</param> | ||
/// <param name="config">The latest config to be added to the front of the <see cref="Settings.Config"/> fallback chain</param> | ||
public void InjectTopLevelFallback(Config config) | ||
{ | ||
if (Config.Contains(config)) | ||
return; | ||
|
||
_fallbackConfig = config.SafeWithFallback(_fallbackConfig); | ||
while(true) | ||
{ | ||
var oldConfig = _fallbackConfig.Value; | ||
var newConfig = config.SafeWithFallback(oldConfig); | ||
if (_fallbackConfig.CompareAndSet(oldConfig, newConfig)) | ||
break; | ||
} | ||
Comment on lines
+52
to
+58
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix: Do not assign value to naked field directly, this can cause race condition if multiple Akka extensions running in multiple threads tries to start at the same time. Scenario:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. LGTM |
||
|
||
RebuildConfig(); | ||
} | ||
|
||
|
@@ -77,7 +85,7 @@ public Settings(ActorSystem system, Config config, ActorSystemSetup setup) | |
{ | ||
Setup = setup; | ||
_userConfig = config; | ||
_fallbackConfig = ConfigurationFactory.Default(); | ||
_fallbackConfig = new AtomicReference<Config>(ConfigurationFactory.Default()); | ||
RebuildConfig(); | ||
|
||
System = system; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, this is a much simpler fix than what I was imagining