Skip to content

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

Open
@SanjayVas

Description

@SanjayVas

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 parallel1, 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:

In these cases DebugProbes.install is called via CoroutinesTimeout.

Footnotes

  1. See documentation for Bazel for more information on how it runs tests in parallel.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions