Skip to content

[Nullable] Convert ActorState#7990

Open
Arkatufus wants to merge 12 commits intoakkadotnet:devfrom
Arkatufus:nullable/convert-ActorState
Open

[Nullable] Convert ActorState#7990
Arkatufus wants to merge 12 commits intoakkadotnet:devfrom
Arkatufus:nullable/convert-ActorState

Conversation

@Arkatufus
Copy link
Contributor

Changes

Enable nullability on Akka.Actor.ActorState.

Behavior Change

ActorState.GetCurrentBehavior() now throws IllegalActorStateException if the current actor behavior is null/undefined.

@Aaronontheweb
Copy link
Member

Analysis of Windows Test Failures

The Windows-specific test failures in this PR appear to be caused by a behavioral change introduced by the nullable annotations, not flaky tests.

The Change

Before this PR, GetCurrentBehavior() would return null if the behavior was uninitialized:

private Receive _receive;
public Receive GetCurrentBehavior() => _receive;

After this PR, it throws an exception:

private Receive? _receive;
public Receive GetCurrentBehavior()
{
    return _receive ?? throw new IllegalActorStateException(
        "Attempted to access an Actor's behavior before it has been initialized.");
}

Why Windows-Only?

Windows CI runs tests with different parallelism settings than Linux. This exposes race conditions where GetCurrentBehavior() is called during actor lifecycle transitions when the behavior is temporarily null or the behavior stack is empty. These code paths previously returned null silently but now throw exceptions.

Potential Solutions

  1. Keep the exception but fix callers: Find code paths that call GetCurrentBehavior() before initialization and add appropriate guards
  2. Return a safe default: Instead of throwing, return a behavior that forwards to dead letters
  3. Add a TryGetCurrentBehavior() method: Allow callers to check without throwing

The exit code -1 (rather than specific test failures) suggests the exception is being thrown in a context where it crashes the test process rather than failing a specific test gracefully.


Analysis generated while investigating flaky tests in the Akka.NET codebase.

@Aaronontheweb
Copy link
Member

LLM analysis comment up there, but this came from a session where I've been bulk-reviewing racy tests across 7-10 PRs. Agree that that seems like a potential problem from a behavioral standpoint.

@Arkatufus
Copy link
Contributor Author

That is really weird, because GetCurrentBehavior() only get used in ActorCell.ReceiveMessage() and will cause an NRE if its null.

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.

2 participants