Skip to content

Commit c521b50

Browse files
committed
fix(virtual-thread): Preload scope classes to prevent virtual thread deadlock
Preload ScopeContext and ScopeStack classes in ContinuableScopeManager constructor to avoid class loading on virtual thread mount path. DatadogClassLoader's synchronized I/O from JarFile can pin carrier threads and deadlock the application.
1 parent e95e91e commit c521b50

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

dd-java-agent/instrumentation/java/java-lang/java-lang-21.0/src/main/java/datadog/trace/instrumentation/java/lang/jdk21/VirtualThreadInstrumentation.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,22 @@ public final class VirtualThreadInstrumentation extends InstrumenterModule.Conte
6666
Instrumenter.HasMethodAdvice,
6767
ExcludeFilterProvider {
6868

69+
// Preload classes used by Context.swap() to avoid class loading on the virtual thread mount path.
70+
// DatadogClassLoader loads these from a JarFile using synchronized I/O, which pins
71+
// virtual thread carrier threads and can deadlock the application.
72+
private static final String[] PRELOAD_CLASS_NAMES = {
73+
"datadog.trace.core.scopemanager.ScopeContext", "datadog.trace.core.scopemanager.ScopeStack"
74+
};
75+
6976
public VirtualThreadInstrumentation() {
7077
super("java-lang", "java-lang-21", "virtual-thread");
7178
}
7279

80+
@Override
81+
public String[] preloadClassNames() {
82+
return PRELOAD_CLASS_NAMES;
83+
}
84+
7385
@Override
7486
public String instrumentedType() {
7587
return VIRTUAL_THREAD_CLASS_NAME;

0 commit comments

Comments
 (0)