-
Notifications
You must be signed in to change notification settings - Fork 1k
Description
Describe the bug
In io.opentelemetry.instrumentation.runtimemetrics.java17 RuntimeMetrics starts JFR via RecordingStream on a separate daemon thread. If a caller creates RuntimeMetrics and then quickly calls close() the background thread may invoke RecordingStream.start() after the stream has already been closed. Has anyone seen this issue?
Steps to reproduce
I am able to reproduce it locally very simply by doing the following:
var otel = OpenTelemetrySdk.builder().build();
for (int i = 0; i < 50; i++) {
var runtime = RuntimeMetrics.builder(otel)
.enableAllFeatures()
.build();
runtime.close();
}
Expected behavior
There should probably be a solution to synchronously start/stop or expose a flag/hook to check that the JFR started before the user calls close.
Actual behavior
JFR throws:
java.lang.IllegalStateException: Recording can only be started once.
Javaagent or library instrumentation version
2.21.0-alpha
Environment
OpenJDK Runtime Environment Temurin-21.0.6+7
macOS: Sequoia 15.7.1
Additional context
Found this on 2.11.0-alpha but also still appeared when testing this with 2.21.0-alpha
Tip
React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding +1 or me too, to help us triage it. Learn more here.