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

Actor with Behaviors.echo caused "Object reference not set to an instance of an object" exception #136

Open
ingted opened this issue Dec 28, 2020 · 4 comments

Comments

@ingted
Copy link

ingted commented Dec 28, 2020



#r "nuget: Akka.Serialization.Hyperion"
#r "nuget: Akka.Cluster"
#r "nuget: Akka.Remote"
#r "nuget: Akka.Cluster.Tools"
#r "nuget: Akkling"
#r "nuget: Akkling.Cluster.Sharding"
#r "nuget: Microsoft.Extensions.Logging"
#r "nuget: Microsoft.Extensions.Logging.Abstractions"

open System
open Akka.Cluster
open Akkling
open Akkling.Cluster
open Akka.Actor


let configWithPort port =
    let config = Configuration.parse ("""
        akka {
            actor {
              provider = "Akka.Cluster.ClusterActorRefProvider, Akka.Cluster"
              serializers {
                hyperion = "Akka.Serialization.HyperionSerializer, Akka.Serialization.Hyperion"
              }
              serialization-bindings {
                "System.Object" = hyperion
              }
            }
          remote {
            dot-netty.tcp {
              public-hostname = "localhost"
              hostname = "localhost"
              port = """ + port.ToString() + """
            }
          }
          cluster {
            auto-down-unreachable-after = 5s
            seed-nodes = [ "akka.tcp://cluster-system@localhost:5000/" ]
          }
          persistence {
            journal.plugin = "akka.persistence.journal.inmem"
            snapshot-store.plugin = "akka.persistence.snapshot-store.local"
          }
        }
        """)
    config.WithFallback(Akka.Cluster.Tools.Singleton.ClusterSingletonManager.DefaultConfig())

let system = Akkling.System.create "cluster-system" <| (configWithPort 5000)
let ttc111:IActorRef<obj> = spawn system ("ttc111" + Guid.NewGuid().ToString()) (props (Behaviors.echo))
let ttc112:IActorRef<obj> = spawn system ("ttc112" + Guid.NewGuid().ToString()) (props (Behaviors.printf "%A"))
ttc111.Tell(box "fff", untyped ttc112)

The above code caused error:

[ERROR][12/28/2020 4:35:34 AM][Thread 0050][akka://cluster-system/user/ttc1113a4e6ed4-262d-4b16-b741-d9754d86a916] Object reference not set to an instance of an object.
Cause: [akka://cluster-system/user/ttc1113a4e6ed4-262d-4b16-b741-d9754d86a916#623827306]: Akka.Actor.ActorInitializationException: Exception during creation ---> System.NullReferenceException: Object reference not set to an instance of an object.
   at Akkling.ActorRefs.TypedActorRef`1.Akkling-ActorRefs-ICanTell`1-Tell(Message message, IActorRef sender)
   at Akkling.Behaviors.loop@28-10.Invoke(Message _arg1)
   at Akkling.Actors.FunActor`1.Handle(Object msg)
   at Akka.Actor.ActorBase.AroundPreStart()
   at Akka.Actor.ActorCell.<>c__DisplayClass176_0.<Create>b__0()
   at Akka.Actor.ActorCell.UseThreadContext(Action action)
   at Akka.Actor.ActorCell.Create(Exception failure)
   --- End of inner exception stack trace ---
   at Akka.Actor.ActorCell.Create(Exception failure)
   at Akka.Actor.ActorCell.SysMsgInvokeAll(EarliestFirstSystemMessageList messages, Int32 currentState)
[INFO][12/28/2020 4:35:34 AM][Thread 0022][akka://cluster-system/user/ttc1113a4e6ed4-262d-4b16-b741-d9754d86a916] Message [String] from akka://cluster-system/user/ttc112a0277530-0b18-4757-b1e9-8412296f6f34 to akka://cluster-system/user/ttc1113a4e6ed4-262d-4b16-b741-d9754d86a916 was not delivered. [1] dead letters encountered. If this is not an expected behavior then akka://cluster-system/user/ttc1113a4e6ed4-262d-4b16-b741-d9754d86a916 may have terminated unexpectedly. This logging can be turned off or adjusted with configuration settings 'akka.log-dead-letters' and 'akka.log-dead-letters-during-shutdown'.

Environment:

Microsoft Visual Studio Community 2019 Preview
Version 16.9.0 Preview 1.0

Microsoft (R) F# Interactive version 11.0.0.0 for F# 5.0
Copyright (c) Microsoft Corporation. All Rights Reserved.

fsi parameters:

--optimize- --readline+ --debug+ -d:TRACE --noframework
@Horusiath
Copy link
Owner

Confirmed, it's a bug indeed. Since your Behaviors.echo targets obj, the first message received is not the one to be echo'ed back, but PreStart from an actor itself (sometimes used to setup initial actor state). That message has no sender, it's a lifecycle event. If you change Behaviors.echo<obj> to something else eg. Behaviors.echo<string> the issue will go away.

@ingted
Copy link
Author

ingted commented Dec 28, 2020

Got it!!

@ingted
Copy link
Author

ingted commented Dec 29, 2020

#104 Is this very similar with issue 104?

@Horusiath
Copy link
Owner

Yes, it looks like they may have the same root cause.

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

No branches or pull requests

2 participants