newrelic / newrelic-java-kotlin-coroutines

Provides instrumentation for Kotlin Coroutines
Apache License 2.0
1 stars 4 forks source link

NullPointerException being thrown in "com.newrelic.agent.Transaction.finishSegment" #36

Open gillesbergerp opened 1 month ago

gillesbergerp commented 1 month ago

Description

We experience NullPointerExceptions when using the coroutine extension with Java agent version 8.15.0. Removing the extension (but staying on the same agent version) does not result in the problem

Relevant Logs / Console output

java.lang.NullPointerException:
 Cannot invoke 
"com.newrelic.agent.Transaction.finishSegment(com.newrelic.agent.Segment,
 java.lang.Throwable, com.newrelic.agent.tracers.Tracer, String)" 
because the return value of 
"com.newrelic.agent.TransactionActivity.getTransaction()" is null
    at com.newrelic.agent.Segment$1.run(Segment.java:203)
    at 
com.newrelic.agent.ExpirationService.expireSegmentInline(ExpirationService.java:47)
    at com.newrelic.agent.Segment.finish(Segment.java:215)
    at com.newrelic.agent.Segment.end(Segment.java:144)
    at 
com.nr.agent.mongo.NRCallbackWrapper.onResult(NRCallbackWrapper.java:48)
    at 
com.mongodb.internal.async.ErrorHandlingResultCallback.onResult(ErrorHandlingResultCallback.java:47)
    at 
com.mongodb.internal.async.function.AsyncCallbackSupplier.lambda$whenComplete$1(AsyncCallbackSupplier.java:97)
    at 
com.mongodb.internal.async.function.RetryingAsyncCallbackSupplier$RetryingCallback.onResult(RetryingAsyncCallbackSupplier.java:116)
    at 
com.mongodb.internal.async.ErrorHandlingResultCallback.onResult(ErrorHandlingResultCallback.java:47)
    at 
com.mongodb.internal.async.function.AsyncCallbackSupplier.lambda$whenComplete$1(AsyncCallbackSupplier.java:97)
    at 
com.mongodb.internal.async.ErrorHandlingResultCallback.onResult(ErrorHandlingResultCallback.java:47)
    at 
com.mongodb.internal.async.function.AsyncCallbackSupplier.lambda$whenComplete$1(AsyncCallbackSupplier.java:97)
    at 
com.mongodb.internal.operation.FindOperation.lambda$exceptionTransformingCallback$6(FindOperation.java:369)
    at 
com.mongodb.internal.operation.AsyncOperationHelper.lambda$transformingReadCallback$19(AsyncOperationHelper.java:442)
    at 
com.mongodb.internal.async.ErrorHandlingResultCallback.onResult(ErrorHandlingResultCallback.java:47)
    at 
com.mongodb.internal.connection.LoadBalancedServer$LoadBalancedServerProtocolExecutor.lambda$executeAsync$0(LoadBalancedServer.java:186)
    at 
com.mongodb.internal.async.ErrorHandlingResultCallback.onResult(ErrorHandlingResultCallback.java:47)
    at 
com.mongodb.internal.connection.CommandProtocolImpl.lambda$executeAsync$0(CommandProtocolImpl.java:88)
    at 
com.mongodb.internal.connection.DefaultConnectionPool$PooledConnection.lambda$sendAndReceiveAsync$1(DefaultConnectionPool.java:802)
    at 
com.mongodb.internal.connection.UsageTrackingInternalConnection.lambda$sendAndReceiveAsync$1(UsageTrackingInternalConnection.java:155)
    at 
com.mongodb.internal.async.ErrorHandlingResultCallback.onResult(ErrorHandlingResultCallback.java:47)
    at 
com.mongodb.internal.connection.InternalStreamConnection.lambda$sendCommandMessageAsync$0(InternalStreamConnection.java:555)
    at 
com.mongodb.internal.connection.InternalStreamConnection$MessageHeaderCallback$MessageCallback.onResult(InternalStreamConnection.java:849)
    at 
com.mongodb.internal.connection.InternalStreamConnection$MessageHeaderCallback$MessageCallback.onResult(InternalStreamConnection.java:812)
    at 
com.mongodb.internal.connection.InternalStreamConnection$3.completed(InternalStreamConnection.java:671)
    at 
com.mongodb.internal.connection.InternalStreamConnection$3.completed(InternalStreamConnection.java:668)
    at 
com.mongodb.internal.connection.AsynchronousChannelStream$BasicCompletionHandler.completed(AsynchronousChannelStream.java:252)
    at 
com.mongodb.internal.connection.AsynchronousChannelStream$BasicCompletionHandler.completed(AsynchronousChannelStream.java:235)
    at java.base/sun.nio.ch.Invoker.invokeUnchecked(Unknown Source)
    at java.base/sun.nio.ch.Invoker.invokeDirect(Unknown Source)
    at 
java.base/sun.nio.ch.UnixAsynchronousSocketChannelImpl.implRead(Unknown 
Source)
    at java.base/sun.nio.ch.AsynchronousSocketChannelImpl.read(Unknown 
Source)
    at java.base/sun.nio.ch.AsynchronousSocketChannelImpl.read(Unknown 
Source)
    at 
com.mongodb.internal.connection.AsynchronousSocketChannelStream$AsynchronousSocketChannelAdapter.read(AsynchronousSocketChannelStream.java:148)
    at 
com.mongodb.internal.connection.AsynchronousChannelStream.readAsync(AsynchronousChannelStream.java:124)
    at 
com.mongodb.internal.connection.AsynchronousChannelStream.readAsync(AsynchronousChannelStream.java:113)
    at 
com.mongodb.internal.connection.InternalStreamConnection.readAsync(InternalStreamConnection.java:668)
    at 
com.mongodb.internal.connection.InternalStreamConnection.access$600(InternalStreamConnection.java:98)
    at 
com.mongodb.internal.connection.InternalStreamConnection$MessageHeaderCallback.onResult(InternalStreamConnection.java:802)
    at 
com.mongodb.internal.connection.InternalStreamConnection$MessageHeaderCallback.onResult(InternalStreamConnection.java:786)
    at 
com.mongodb.internal.connection.InternalStreamConnection$3.completed(InternalStreamConnection.java:671)
    at 
com.mongodb.internal.connection.InternalStreamConnection$3.completed(InternalStreamConnection.java:668)
    at 
com.mongodb.internal.connection.AsynchronousChannelStream$BasicCompletionHandler.completed(AsynchronousChannelStream.java:252)
    at 
com.mongodb.internal.connection.AsynchronousChannelStream$BasicCompletionHandler.comple<!--EndFragment-->

Your Environment

dhilpipre commented 1 month ago

We are working on this problem. it results from problems with the Java Agent and the Kotlin-Coroutines-Suspends.jar.
As a workaround, remove the Kotlin-Coroutines-Suspends.jar from the extensions directory and restart. This should eliminate the problem but will result in Suspend methods not being tracked.

All other extension are fine and do not cause problems.

gillesbergerp commented 1 month ago

Thanks for the fast reply. Is there an ETA for when a fix might be available?

dhilpipre commented 1 month ago

The problem seems to stem from a problem when the Java Agent retransforms some Kotlin classes. I can't give an ETA until I have been able to work with them on fixing that problem but indications are that it might be a while.