Skip to content

Nullpointer exception for pekko-instrumentation in version 1.1.0-M1 onward #1352

@TjarkoG

Description

@TjarkoG

when testing pekko with the version 1.1.0-M1 which will be released soon we've ran into a nullpointer error when running with Kamon + kanela-instrumentation.

to Reproduce:
build.sbt

name := "pekko-quickstart-scala"

version := "1.0"

scalaVersion := "2.13.14"

lazy val pekkoVersion = "1.1.0-M1"

run/fork := true

libraryDependencies ++= Seq(
  "org.apache.pekko" %% "pekko-actor-typed" % pekkoVersion,
  "org.apache.pekko" %% "pekko-http" % pekkoVersion,
  "org.apache.pekko" %% "pekko-stream" % pekkoVersion,
  "ch.qos.logback" % "logback-classic" % "1.5.6",
  "io.kamon" %% "kamon-pekko" % "2.7.3",
  "io.kamon" %% "kamon-system-metrics" % "2.7.3",
  "io.kamon" %% "kamon-prometheus" % "2.7.3"
)

Main.scala:

//#full-example
package com.example

import com.typesafe.config.ConfigFactory
import org.apache.pekko.actor.ActorSystem
import org.apache.pekko.http.scaladsl.Http
import org.apache.pekko.http.scaladsl.client.RequestBuilding.Get
import org.apache.pekko.http.scaladsl.server.Directives

object Main extends Directives {
  def main(args: Array[String]): Unit = {
    val config = ConfigFactory.load()
    implicit val untyped: ActorSystem = ActorSystem.create("Test", config)
    Http()(untyped).singleRequest(Get("https://www.google.com")).onComplete(rsp => println(rsp.map(_.status)))(untyped.dispatcher)
  }
}

when starting with -javaagent:javaagent/kanela-agent.jar (version 1.0.18)

i'm receiving the exception:

org.apache.pekko.actor.ActorInitializationException: pekko://Test/system/IO-TCP/selectors/$a: exception during creation, root cause message: [Cannot invoke "org.apache.pekko.dispatch.DispatcherPrerequisites.settings()" because the return value of "kamon.instrumentation.pekko.instrumentations.DispatcherInfo$HasDispatcherPrerequisites.dispatcherPrerequisites()" is null]
	at org.apache.pekko.actor.ActorCell.create(ActorCell.scala:679)
	at org.apache.pekko.actor.ActorCell.invokeAll$1(ActorCell.scala:523)
	at org.apache.pekko.actor.ActorCell.systemInvoke(ActorCell.scala:545)
	at org.apache.pekko.dispatch.Mailbox.processAllSystemMessages(Mailbox.scala:297)
	at org.apache.pekko.dispatch.Mailbox.run(Mailbox.scala:232)
	at kamon.instrumentation.executor.ExecutorInstrumentation$InstrumentedForkJoinPool$TimingRunnable.run(ExecutorInstrumentation.scala:800)
	at org.apache.pekko.dispatch.ForkJoinExecutorConfigurator$PekkoForkJoinTask.exec(ForkJoinExecutorConfigurator.scala:61)
	at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:373)
	at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1182)
	at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1655)
	at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1622)
	at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:165)
Caused by: java.lang.reflect.InvocationTargetException: null
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
	at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:480)
	at org.apache.pekko.util.Reflect$.instantiate(Reflect.scala:82)
	at org.apache.pekko.actor.ArgsReflectConstructor.produce(IndirectActorProducer.scala:111)
	at org.apache.pekko.actor.Props.newActor(Props.scala:236)
	at org.apache.pekko.actor.ActorCell.newActor(ActorCell.scala:626)
	at org.apache.pekko.actor.ActorCell.create(ActorCell.scala:653)
	... 11 common frames omitted
Caused by: java.lang.NullPointerException: Cannot invoke "org.apache.pekko.dispatch.DispatcherPrerequisites.settings()" because the return value of "kamon.instrumentation.pekko.instrumentations.DispatcherInfo$HasDispatcherPrerequisites.dispatcherPrerequisites()" is null
	at kamon.instrumentation.pekko.instrumentations.InstrumentNewExecutorServiceOnPekko$.around(DispatcherInstrumentation.scala:130)
	at kamon.instrumentation.pekko.instrumentations.InstrumentNewExecutorServiceOnPekko.around(DispatcherInstrumentation.scala)
	at org.apache.pekko.dispatch.ThreadPoolConfig$ThreadPoolExecutorServiceFactory.createExecutorService(ThreadPoolBuilder.scala)
	at org.apache.pekko.dispatch.Dispatcher$LazyExecutorServiceDelegate.executor$lzycompute(Dispatcher.scala:54)
	at org.apache.pekko.dispatch.Dispatcher$LazyExecutorServiceDelegate.executor(Dispatcher.scala:54)
	at org.apache.pekko.dispatch.ExecutorServiceDelegate.execute(ThreadPoolBuilder.scala:232)
	at org.apache.pekko.dispatch.ExecutorServiceDelegate.execute$(ThreadPoolBuilder.scala:232)
	at org.apache.pekko.dispatch.Dispatcher$LazyExecutorServiceDelegate.execute(Dispatcher.scala:53)
	at org.apache.pekko.dispatch.Dispatcher.executeTask(Dispatcher.scala:91)
	at org.apache.pekko.dispatch.MessageDispatcher.unbatchedExecute(AbstractDispatcher.scala:177)
	at org.apache.pekko.dispatch.BatchingExecutor.execute(BatchingExecutor.scala:143)
	at org.apache.pekko.dispatch.BatchingExecutor.execute$(BatchingExecutor.scala:134)
	at org.apache.pekko.dispatch.MessageDispatcher.execute(AbstractDispatcher.scala:107)
	at org.apache.pekko.util.SerializedSuspendableExecutionContext.attach(SerializedSuspendableExecutionContext.scala:92)
	at org.apache.pekko.util.SerializedSuspendableExecutionContext.execute(SerializedSuspendableExecutionContext.scala:95)
	at org.apache.pekko.io.SelectionHandler$ChannelRegistryImpl.<init>(SelectionHandler.scala:200)
	at org.apache.pekko.io.SelectionHandler.<init>(SelectionHandler.scala:324)
	... 21 common frames omitted

i've tried to analyze the error and got to the point that
kamon/instrumentation/pekko/instrumentations/DispatcherInstrumentation.scala:164
does not seem to get triggered with pekko 1.1.0-M1 anymore resulting in dispatcherPrerequisites being null in
kamon/instrumentation/pekko/instrumentations/DispatcherInstrumentation.scala:125
but i cannot understand what change in pekko 1.0.3 <-> 1.1.0-M1 made that difference and how to fix it

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions