Skip to content

In RemotingTerminator, avoid racy FSM log init.#7967

Merged
Aaronontheweb merged 3 commits into
akkadotnet:devfrom
gunjambi:fix-racy-remoting-terminator-fsm-log-init
Dec 18, 2025
Merged

In RemotingTerminator, avoid racy FSM log init.#7967
Aaronontheweb merged 3 commits into
akkadotnet:devfrom
gunjambi:fix-racy-remoting-terminator-fsm-log-init

Conversation

@gunjambi
Copy link
Copy Markdown
Contributor

Fixes #7966

Changes

This PR removes the use of FSM from RemotingTerminator and manually implements it using Become() API.

RemotingTerminator is initialized during Provider Start. FSM constructor
initializes the _log with `context.GetLogger()` which eventually leads into
`LogSource.FromActorRef()`. This method attempts to access
`Provider.DefaultAddress`, which is being initialized.

If Provider `Init()` loses the race, either its `RemoteInternals` is not set,
causing NRE, or if `Remoting.Start()` is not completed, the `_defaultAddress`
is not set and returns null.

This commit removes the FSM from `RemotingTerminator` and manually implements
it using `Become()` API.
@Arkatufus
Copy link
Copy Markdown
Contributor

I don't see this fixing anything, it's just replacing FSM with .Become() semantic. Can you point to the code that fixes the FSM log init race condition?

@Aaronontheweb
Copy link
Copy Markdown
Member

Looks like AI slop to me

@gunjambi
Copy link
Copy Markdown
Contributor Author

Looks like AI slop to me

It's 100% human labor. AI doesn't give a heck about caught exceptions. I do since I need to configure the debugger to ignore this same error every time I create a new project. This has been my pet peeve for years, and finally decided to do something about it.

If you are worried I'm trying to make a name for myself or something silly, please do edit the author field as needed.

Can you point to the code that fixes the FSM log init race condition?

As it says, it removes the use of FSM from RemotingTerminator here

https://github.com/akkadotnet/akka.net/pull/7967/files#diff-8c2209c249f2cface28f390ededbe67415107fa019bc998f4b3f173cb7b0a7d5L715-R688

As mentioned in the issue: "RemotingTerminator inherits from FSM and FSM constructor initializes the _log with context.GetLogger() which":

https://github.com/akkadotnet/akka.net/blob/dev/src/core/Akka/Actor/FSM.cs#L685-L687

@Aaronontheweb Aaronontheweb reopened this Dec 17, 2025
@Aaronontheweb
Copy link
Copy Markdown
Member

@gunjambi my apologies - it just looked like a drive-by PR with an AI-generated branch name to me.

@Aaronontheweb
Copy link
Copy Markdown
Member

Let me do a review here and see what I can see

Copy link
Copy Markdown
Member

@Aaronontheweb Aaronontheweb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Aaronontheweb
Copy link
Copy Markdown
Member

@gunjambi this looks good - truly, my sincere apologies for being too quick to judge earlier

@Aaronontheweb Aaronontheweb merged commit 6e509d2 into akkadotnet:dev Dec 18, 2025
11 checks passed
Arkatufus pushed a commit to Arkatufus/akka.net that referenced this pull request Jan 7, 2026
…et#7967)

RemotingTerminator is initialized during Provider Start. FSM constructor
initializes the _log with `context.GetLogger()` which eventually leads into
`LogSource.FromActorRef()`. This method attempts to access
`Provider.DefaultAddress`, which is being initialized.

If Provider `Init()` loses the race, either its `RemoteInternals` is not set,
causing NRE, or if `Remoting.Start()` is not completed, the `_defaultAddress`
is not set and returns null.

This commit removes the FSM from `RemotingTerminator` and manually implements
it using `Become()` API.

Co-authored-by: Aaron Stannard <aaron@petabridge.com>
Aaronontheweb added a commit that referenced this pull request Jan 8, 2026
RemotingTerminator is initialized during Provider Start. FSM constructor
initializes the _log with `context.GetLogger()` which eventually leads into
`LogSource.FromActorRef()`. This method attempts to access
`Provider.DefaultAddress`, which is being initialized.

If Provider `Init()` loses the race, either its `RemoteInternals` is not set,
causing NRE, or if `Remoting.Start()` is not completed, the `_defaultAddress`
is not set and returns null.

This commit removes the FSM from `RemotingTerminator` and manually implements
it using `Become()` API.

Co-authored-by: Aaron Stannard <aaron@petabridge.com>
This was referenced May 21, 2026
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.

Race condition in Akka.Remote RemoteActorRefProvider initialization

3 participants