-
Notifications
You must be signed in to change notification settings - Fork 6.2k
8365066: RecordingStream and RemoteRecordingStream do not terminate when the associated Recording is stopped or closed externally #26710
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
👋 Welcome back cito! A progress list of the required criteria for merging this PR into |
❗ This change is not yet ready to be integrated. |
Did you look into adding a FlightRecorderListener and implementing recordingStateChanged to check if the RecordingState is CLOSED and then call close() on the stream? Or perhaps it would be better to set a flag and let the thread running the stream close itself after the next flush is complete. For a RemoteRecordingStream there is a JMX notification that can be listened on. |
private static class SendEventListener implements FlightRecorderListener { | ||
@Override | ||
public void recordingStateChanged(Recording recording) { | ||
if(recording.getState() == RecordingState.RUNNING){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if(recording.getState() == RecordingState.RUNNING){ | |
if (recording.getState() == RecordingState.RUNNING){ |
private static class SendEventListener implements FlightRecorderListener { | ||
@Override | ||
public void recordingStateChanged(Recording recording) { | ||
if(recording.getState() == RecordingState.RUNNING){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if(recording.getState() == RecordingState.RUNNING){ | |
if (recording.getState() == RecordingState.RUNNING){ |
@@ -469,7 +467,9 @@ public void close() { | |||
ManagementSupport.setOnChunkCompleteHandler(stream, null); | |||
stream.close(); | |||
try { | |||
mbean.closeRecording(recordingId); | |||
if(eventSource.getState() != RecordingState.CLOSED) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if(eventSource.getState() != RecordingState.CLOSED) { | |
if (eventSource.getState() != RecordingState.CLOSED) { |
} | ||
|
||
@Override | ||
public RecordingState getState() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public RecordingState getState() { | |
public RecordingState getState() { | |
@@ -169,6 +167,19 @@ protected void processRecursionSafe() throws IOException { | |||
"ns (epoch), parser at " + lastFlush + "ns (epoch)."); | |||
return; | |||
} | |||
|
|||
if(!barrier.used()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if(!barrier.used()) { | |
if (!barrier.used()) { |
if (isRecordingStream()) { | ||
if (recording.getState() == RecordingState.STOPPED && !barrier.used()) { | ||
logStreamEnd("recording stopped externally."); | ||
if(!barrier.used()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if(!barrier.used()) { | |
if (!barrier.used()) { |
if (state == RecordingState.CLOSED){ | ||
logStreamEnd("Event source is closed externally"); | ||
return; | ||
}else if(state == RecordingState.STOPPED) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
}else if(state == RecordingState.STOPPED) { | |
} else if (state == RecordingState.STOPPED) { |
private static class SendEventListener implements FlightRecorderListener{ | ||
@Override | ||
public void recordingStateChanged(Recording recording) { | ||
if(recording.getState() == RecordingState.RUNNING){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if(recording.getState() == RecordingState.RUNNING){ | |
if (recording.getState() == RecordingState.RUNNING){ |
private static class SendEventListener implements FlightRecorderListener { | ||
@Override | ||
public void recordingStateChanged(Recording recording) { | ||
if(recording.getState() == RecordingState.RUNNING){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if(recording.getState() == RecordingState.RUNNING){ | |
if (recording.getState() == RecordingState.RUNNING){ |
@@ -40,21 +41,44 @@ | |||
*/ | |||
public class TestStoppedRecording { | |||
|
|||
private static class SendEventListener implements FlightRecorderListener{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
private static class SendEventListener implements FlightRecorderListener{ | |
private static class SendEventListener implements FlightRecorderListener { |
@Override | ||
public long getStopTime() { | ||
Optional<RecordingInfo> recordingInfo = mbean.getRecordings().stream().filter(r -> r.getId() == recordingId).findFirst(); | ||
if(recordingInfo.isEmpty()){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if(recordingInfo.isEmpty()){ | |
if (recordingInfo.isEmpty()){ |
} | ||
|
||
@Override | ||
public RecordingState getState() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public RecordingState getState() { | |
public RecordingState getState() { | |
@Override | ||
public RecordingState getState() { | ||
Optional<RecordingInfo> recordingInfo = mbean.getRecordings().stream().filter(r -> r.getId() == recordingId).findFirst(); | ||
if(recordingInfo.isEmpty()){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if(recordingInfo.isEmpty()){ | |
if (recordingInfo.isEmpty()){ | |
public RecordingState getState() { | ||
Optional<RecordingInfo> recordingInfo = mbean.getRecordings().stream().filter(r -> r.getId() == recordingId).findFirst(); | ||
if(recordingInfo.isEmpty()){ | ||
return RecordingState.CLOSED; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return RecordingState.CLOSED; | |
return RecordingState.CLOSED; | |
@egahlin That sounds like a good idea. I’ll give it a try. |
…hen the associated Recording is stopped or closed externally
27b52e6
to
5b437d7
Compare
@chiroito Please do not rebase or force-push to an active PR as it invalidates existing review comments. Note for future reference, the bots always squash all changes into a single commit automatically as part of the integration. See OpenJDK Developers’ Guide for more information. |
@egahlin |
This will take me some time to go through. I'm a little bit worried about the locking, but I need to investigate, before I can comment further. |
I apologize. I do have one question: is there a general preference between using synchronized and ReentrantLock? |
The preference is to not use locks at all when callbacks (listeners) are being invoked as it could potentially lead to dead locks. Best would be if a flag can be set so the stream stops or closes itself at the next flush, but again, I haven't had time to look at it, so it might not be feasible. Best behavior would be if an external stop or close acted as an internal one. The code with the stream barrier is complex, but it was needed to ensure all subscribed events emitted before a stop gets an onEvent(...) callback. |
I've looked into the issue, and I'm not sure a RemoteRecordingStream should be closed if the underlying recording is.
I have implemented the above changes. You can look at it here #27025 I noticed that the underlying Recording object may be exposed before the stream has been initialized, so I added synchronization. Now, any other thread trying to get a recording will have to wait for the RecordingStream initialization to complete. |
Fix an issue where RecordingStream and RemoteRecordingStream do not stop when their underlying the local/remote recording stop.
Introduce an internal EventSource abstraction to unify control across local (PlatformRecording) and remote (FlightRecorderMXBean) recordings, ensuring consistent propagation of stop/close and stop time to the consumer streams.
Tests updated to validate lifecycle consistency:
Verifies that stopping/closing the underlying recording (local and remote) properly stops/closes the corresponding stream.
Test: jdk/jdk/jfr
Progress
Issue
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/26710/head:pull/26710
$ git checkout pull/26710
Update a local copy of the PR:
$ git checkout pull/26710
$ git pull https://git.openjdk.org/jdk.git pull/26710/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 26710
View PR using the GUI difftool:
$ git pr show -t 26710
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/26710.diff
Using Webrev
Link to Webrev Comment