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

Make sure the 2nd call to shutdown() on the GRPC exporters succeeds. #3307

Merged
merged 2 commits into from
Jun 10, 2021

Conversation

jkwatson
Copy link
Contributor

Resolves #3306

@@ -179,6 +179,9 @@ public static OtlpGrpcSpanExporter getDefault() {
*/
@Override
public CompletableResultCode shutdown() {
if (managedChannel.isShutdown()) {
return CompletableResultCode.ofSuccess();
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's definitely still a race condition in here, where the shutdown can complete in between this check and the addition of the 2nd notification listener. I'm not sure if there's a solution to that or not.

Choose a reason for hiding this comment

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

can you add the listener first and do it like this?

final CompletableResultCode result = new CompletableResultCode();
managedChannel.notifyWhenStateChanged(ConnectivityState.SHUTDOWN, result::succeed);
if (managedChannel.isShutdown()) {
  return result.succeed();
}
managedChannel.shutdown();

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That does seem tighter. Depending on the grpc internals, there might still be a race, but this change will definitely make it less likely. Thanks for the suggestion!

@anuraaga anuraaga merged commit be58d03 into open-telemetry:main Jun 10, 2021
@jkwatson jkwatson deleted the double_shutdown branch June 10, 2021 23:52
andimiller added a commit to andimiller/natchez that referenced this pull request Jun 11, 2021
This adds a `natchez-opentelemetry` module which allows span reporting via the `opentelemetry-java` project.

The `Utils` object contains a helper to turn the `OpenTelemetry` `CompletableResultCode` class into an `F[Unit]` given `Async[F]`, this is useful for implementing `Resource`s for clean shutdown logic.

`Shutdownable` is a little abstraction to unify all the interfaces that have a `shutdown(): CompletableResultCode` method in `OpenTelemetry`, since they have no common interface.

`OpenTelemetrySpan` and `OpenTelemetryEntryPoint` are heavily based on the `natchez-jaeger` versions, with tweaks to make them with with `OpenTelemetry.

The `OpenTelemetry` object which end users should interact with has these methods:
* `lift` can be used to lift any `F[T]` where `T` is an `OpenTelemetry` class with a `shutdown` method into a `Resource[F, T], it asks for a name to provide a nice error message
* `entryPoint` is the main way to make an `EntryPoint` and has a boolean flag to allow the user to globally register the `OpenTelemetry` if that's helpful, this defaults to false.
* `globalEntryPoint` will use the globally registered `OpenTelemetry` to create an `EntryPoint`

Note that this is currently using `OpenTelemetry` libraries at `1.4.0-SNAPSHOT` because I found a bug while developing this this broke the shutdown logic.
The issue is here open-telemetry/opentelemetry-java#3306 and it was closed by this PR open-telemetry/opentelemetry-java#3307 so it should make it into the next release.
This was referenced Dec 19, 2021
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.

OtlpGrpcSpanExporter's shutdown can hang forever if the Channel is already shut down
4 participants