kotlinx.coroutines icon indicating copy to clipboard operation
kotlinx.coroutines copied to clipboard

Suspected race condition in DebugProbes.install w.r.t. ByteBuddy

Open SanjayVas opened this issue 2 years ago • 0 comments
trafficstars

Describe the bug

Sometimes DebugProbes.install fails with the following:

Caused by: java.lang.IllegalStateException: The Byte Buddy agent is not installed or not accessible
        at kotlinx.coroutines.repackaged.net.bytebuddy.dynamic.loading.ClassReloadingStrategy.fromInstalledAgent(ClassReloadingStrategy.java:171)
        at kotlinx.coroutines.debug.internal.ByteBuddyDynamicAttach.attach(Attach.kt:29)
        at kotlinx.coroutines.debug.internal.ByteBuddyDynamicAttach.invoke(Attach.kt:17)
        at kotlinx.coroutines.debug.internal.ByteBuddyDynamicAttach.invoke(Attach.kt:15)
        at kotlinx.coroutines.debug.internal.DebugProbesImpl.install(DebugProbesImpl.kt:85)
Caused by: java.lang.reflect.InvocationTargetException
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:566)
        at kotlinx.coroutines.repackaged.net.bytebuddy.dynamic.loading.ClassReloadingStrategy.fromInstalledAgent(ClassReloadingStrategy.java:167)
        ... 11 more
Caused by: java.lang.IllegalStateException: The Byte Buddy agent is not loaded or this method is not called via the system class loader
        at kotlinx.coroutines.repackaged.net.bytebuddy.agent.Installer.getInstrumentation(Installer.java:61)
        ... 16 more

This occurs more frequently when running multiple tests in parallel[^1], so I suspect there's a race condition that is sensitive to load.

JDK version: Azul OpenJDK 11 kotlinx.coroutines version: 1.6.4 (originally reproduced on 1.6.2) Kotlin release version: 1.6.21

Provide a Reproducer

So far I've only reproduced the issue in these large tests:

  • https://github.com/world-federation-of-advertisers/cross-media-measurement/blob/8d0ffec21d8214116313f4c65d609bab84ad6f09/src/test/kotlin/org/wfanet/measurement/integration/deploy/gcloud/GCloudPostgresInProcessLifeOfAMeasurementIntegrationTest.kt
  • https://github.com/world-federation-of-advertisers/cross-media-measurement/blob/8d0ffec21d8214116313f4c65d609bab84ad6f09/src/test/kotlin/org/wfanet/measurement/integration/deploy/gcloud/GCloudSpannerInProcessLifeOfAMeasurementIntegrationTest.kt

In these cases DebugProbes.install is called via CoroutinesTimeout.

[^1]: See documentation for Bazel for more information on how it runs tests in parallel.

SanjayVas avatar Aug 28 '23 22:08 SanjayVas