Skip to content
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

ActorPath.ToStringWithAddress is given null address parameter #6966

Closed
minesworld opened this issue Oct 22, 2023 · 3 comments · Fixed by #7078
Closed

ActorPath.ToStringWithAddress is given null address parameter #6966

minesworld opened this issue Oct 22, 2023 · 3 comments · Fixed by #7078

Comments

@minesworld
Copy link

minesworld commented Oct 22, 2023

Version Information
1.5.13
Remote 1.5.13

Describe the bug
Configuring a simple remote server as in the ChatServer example crashes the program.

Same issue as described on StackOverflow https://stackoverflow.com/questions/69983136/akka-net-net-framework-akka-remote-config-always-errors-on-start-then-works

To Reproduce
Steps to reproduce the behavior:

  1. Download Akka.net github repo
  2. open solution in VS 2022 on Windows 11 22H2
  3. start the ChatServer example

Expected behavior
should just run

Actual behavior
throws System.NullReferenceException

Screenshots
image

Additional context
Adding a check in ActorPath.ToStringWithAddress if the given address is null works (e.g. the server listens), but I have no clue about the side effects and why a null address is given

        private string ToStringWithAddress(Address address, bool includeUid)
        {
            if (address == null ||  IgnoreActorRef.IsIgnoreRefPath(this))
            {
                // we never change address for IgnoreActorRef
                return ToString();
            }

            long? uid = null;
            if (includeUid && _uid != ActorCell.UndefinedUid)
                uid = _uid;

            if (_address.Host != null && _address.Port.HasValue)
                return Join(_address.ToString().AsSpan(), uid);

            return Join(address.ToString().AsSpan(), uid);
        }
minesworld added a commit to minesworld/akka.net that referenced this issue Oct 23, 2023
@Arkatufus
Copy link
Contributor

@minesworld make sure that you have visual studio to ignore handled exceptions.

Not a bug.

@ilmax
Copy link
Contributor

ilmax commented Jan 20, 2024

@Arkatufus sorry to ping you on a closed issue, but I am a bit annoyed by this exception and was checking if there's something I can do to avoid it. It happens to me 100% of the times when starting the application.

Can you point me out to some comments/explain me why this is not a bug?

The exception I'm hitting is from here where system.AsInstanceOf<ExtendedActorSystem>().Provider.DefaultAddress always return null.

What are the issue changing the code to something akin to the following:

public static string FromActorRef(IActorRef a, ActorSystem system)
{
    try
    {
        var defaultAddress = system.AsInstanceOf<ExtendedActorSystem>().Provider.DefaultAddress;
        if (defaultAddress is null)
        {
            return a.Path.ToString();
        }
        return a.Path.ToStringWithAddress(defaultAddress);
    }
    catch // can fail if the ActorSystem (remoting) is not completely started yet
    {
        return a.Path.ToString();
    }
}

@Arkatufus
Copy link
Contributor

Arkatufus commented Jan 30, 2024

@ilmax You can read the original attempt to fix this and the reason why we didn't here: #5454 (comment)

Your fix might be good, we'll look into it.

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 a pull request may close this issue.

3 participants