Akkling icon indicating copy to clipboard operation
Akkling copied to clipboard

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

Open ingted opened this issue 3 years ago • 4 comments



#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 [email protected](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

ingted avatar Dec 28 '20 04:12 ingted

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.

Horusiath avatar Dec 28 '20 12:12 Horusiath

Got it!!

ingted avatar Dec 28 '20 16:12 ingted

#104 Is this very similar with issue 104?

ingted avatar Dec 29 '20 02:12 ingted

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

Horusiath avatar Dec 29 '20 07:12 Horusiath