Skip to content
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

Prevent the runtime attachment from launching multiple times #409

Merged

Conversation

jeanbisutti
Copy link
Member

Prevent the runtime attachment from launching multiple times

@jeanbisutti jeanbisutti requested a review from a team July 21, 2022 14:08
@github-actions github-actions bot requested a review from iNikem July 21, 2022 14:08
@jeanbisutti jeanbisutti marked this pull request as draft July 21, 2022 14:22
@jeanbisutti jeanbisutti marked this pull request as ready for review July 21, 2022 14:29
Comment on lines +42 to +45
if (runtimeAttachmentRequested) {
return;
}
runtimeAttachmentRequested = true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm just wondering, what kind of situations are we trying to prevent here? A simple duplicated line of code? Or runtime attach being called from completely different places in the application? Would it make sense to print out a warning with a stack trace to help pinpoint the unnecessary invocations?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR aims to prevent the runtime attachment from being invoked several times from the main method. If a runtime attachment is invoked while another runtime attachment is in progress and not finished, I am not sure about the result with JVM attachment mechanism. The instrumentation might not be correctly installed.

Would it make sense to print out a warning with a stack trace to help pinpoint the unnecessary invocations?

Nothing is displayed to be consistent with the current display policy. First, this type of message was reported with a debug log. After, the warning log messages were replaced with System.err.println and the debug messages removed. Perhaps it may be worth rediscussing this display policy.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a runtime attachment is invoked while another runtime attachment is in progress and not finished

Again, is that a valid scenario? Don't we already have a check that verifies that only the main thread can call this method?
Otherwise, if a concurrent scenario is possible, then this code needs to be thread safe (use AtomicBoolean instead).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we already have a check that verifies that only the main thread can call this method?
Otherwise, if a concurrent scenario is possible, then this code needs to be thread safe (use AtomicBoolean instead).

The scenario is about two runtime attachments requested from the main thread since the new check is after the main thread check.

Again, is that a valid scenario?

I have not today enough knowledge about the Attach Listener JVM thread implementation. I would prefer to stop the things ealier because it is not the kind of issue I would like to debug. We can close this PR on OTel if you prefer.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to stop the things ealier because it is not the kind of issue I would like to debug.

👍

We can close this PR on OTel if you prefer.

No, I approve of this PR, I think this kind of check definitely makes sense. I was wondering whether this was motivated by a real use case, and if so, what kind of issue it was.

@mateuszrzeszutek mateuszrzeszutek merged commit ca6187a into open-telemetry:main Jul 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants