Skip to content

Commit 4e48384

Browse files
authored
Fix field-injection of ForkJoinTask on Java 25 (#10084)
* Turning off crash-tracking was hiding a bug on Java 25 * Preload a future no-op task to ensure workQueue.take() will use await with timeout during premain - otherwise on Java 25 it will load ForkJoinPool which in turn loads ForkJoinTask, which then means we lose the chance to field-inject context into ForkJoinTask instances * Only apply workaround to the global task scheduler used during premain
1 parent a2f3c7a commit 4e48384

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

dd-smoke-tests/field-injection/src/test/groovy/datadog/smoketest/FieldInjectionSmokeTest.groovy

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ class FieldInjectionSmokeTest extends Specification {
6161
command.add("-XX:ErrorFile=/tmp/hs_err_pid%p.log")
6262
// turn off these features as their debug output can break up our expected logging lines on IBM JVMs
6363
// causing random test failures (we are not testing these features here so they don't need to be on)
64-
command.add("-Ddd.crashtracking.enabled=false")
6564
command.add("-Ddd.instrumentation.telemetry.enabled=false")
6665
command.add("-Ddd.remote_config.enabled=false")
6766
command.add("-Ddd.writer.type=TraceStructureWriter")

internal-api/src/main/java/datadog/trace/util/AgentTaskScheduler.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import static datadog.trace.util.AgentThreadFactory.AgentThread.TASK_SCHEDULER;
55
import static datadog.trace.util.AgentThreadFactory.newAgentThread;
66
import static java.util.concurrent.TimeUnit.MILLISECONDS;
7+
import static java.util.concurrent.TimeUnit.MINUTES;
78
import static java.util.concurrent.TimeUnit.NANOSECONDS;
89
import static java.util.concurrent.TimeUnit.SECONDS;
910

@@ -225,6 +226,12 @@ private void prepareWorkQueue() {
225226
} catch (final InterruptedException e) {
226227
// ignore, we only want to preload queue internals
227228
}
229+
if (this == INSTANCE) {
230+
// preload a future no-op task to ensure workQueue.take() will use await with timeout during
231+
// premain - otherwise on Java 25 it will load ForkJoinPool which in turn loads ForkJoinTask,
232+
// which then means we lose the chance to field-inject context into ForkJoinTask instances
233+
workQueue.offer(FUTURE_NOOP_PLACEHOLDER);
234+
}
228235
}
229236

230237
// for testing
@@ -302,6 +309,9 @@ public void run() {
302309

303310
private static final AtomicInteger TASK_SEQUENCE_GENERATOR = new AtomicInteger();
304311

312+
private static final PeriodicTask<Object> FUTURE_NOOP_PLACEHOLDER =
313+
new PeriodicTask<>(null, new Scheduled<>(null), 10, 0, MINUTES);
314+
305315
private static final class PeriodicTask<T> implements Delayed {
306316

307317
private final Task<T> task;

0 commit comments

Comments
 (0)