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

Manage analytics client to avoid leaks #9611

Merged
merged 1 commit into from
Apr 3, 2024

Conversation

hubertp
Copy link
Contributor

@hubertp hubertp commented Apr 3, 2024

Pull Request Description

This change makes sure to close the Google Analytics client after usage. This will a) ensure that resources are released properly b) potentially fix the exception that is causing problems on some platforms

Important Notes

After this change I no longer see in my logs:

 io.grpc.internal.ManagedChannelOrphanWrapper$ManagedChannelReference cleanQueue
SEVERE: *~*~*~ Previous channel ManagedChannelImpl{logId=1, target=analyticsdata.googleapis.com:443} was not shutdown properly!!! ~*~*~*
    Make sure to call shutdown()/shutdownNow() and wait until awaitTermination() returns true.
java.lang.RuntimeException: ManagedChannel allocation site
	at io.grpc.internal.ManagedChannelOrphanWrapper$ManagedChannelReference.<init>(ManagedChannelOrphanWrapper.java:102)
	at io.grpc.internal.ManagedChannelOrphanWrapper.<init>(ManagedChannelOrphanWrapper.java:60)
	at io.grpc.internal.ManagedChannelOrphanWrapper.<init>(ManagedChannelOrphanWrapper.java:51)
	at io.grpc.internal.ManagedChannelImplBuilder.build(ManagedChannelImplBuilder.java:668)
	at io.grpc.ForwardingChannelBuilder2.build(ForwardingChannelBuilder2.java:260)
	at com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.createSingleChannel(InstantiatingGrpcChannelProvider.java:436)
	at com.google.api.gax.grpc.ChannelPool.<init>(ChannelPool.java:107)
	at com.google.api.gax.grpc.ChannelPool.create(ChannelPool.java:85)
	at com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.createChannel(InstantiatingGrpcChannelProvider.java:243)
	at com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.getTransportChannel(InstantiatingGrpcChannelProvider.java:237)
	at com.google.api.gax.rpc.ClientContext.create(ClientContext.java:226)
	at com.google.analytics.data.v1beta.stub.GrpcBetaAnalyticsDataStub.create(GrpcBetaAnalyticsDataStub.java:217)
	at com.google.analytics.data.v1beta.stub.BetaAnalyticsDataStubSettings.createStub(BetaAnalyticsDataStubSettings.java:288)
	at com.google.analytics.data.v1beta.BetaAnalyticsDataClient.<init>(BetaAnalyticsDataClient.java:376)
	at com.google.analytics.data.v1beta.BetaAnalyticsDataClient.create(BetaAnalyticsDataClient.java:358)
	at org.graalvm.truffle/com.oracle.truffle.host.HostMethodDesc$SingleMethod$MHBase.invokeHandle(HostMethodDesc.java:371)

It's important because apparently that's where it would get stuck when trying to log that message.

Checklist

Please ensure that the following checklist has been satisfied before submitting the PR:

  • All code follows the
    Scala,
    Java,
    and
    Rust
    style guides. In case you are using a language not listed above, follow the Rust style guide.
  • All code has been tested:
    • If GUI codebase was changed, the GUI was tested when built using ./run ide build.

This change makes sure to close the Google Analytics client after usage.
This will a) ensure that resources are released properly b) potentially
fix the exception that is causing problems on some platforms
@hubertp hubertp added the CI: No changelog needed Do not require a changelog entry for this PR. label Apr 3, 2024
@hubertp hubertp added the CI: Ready to merge This PR is eligible for automatic merge label Apr 3, 2024
analytics_data = case credentials of
Google_Credential.Default -> BetaAnalyticsDataClient.create
managed_analytics_data = case credentials of
Google_Credential.Default -> Managed_Resource (BetaAnalyticsDataClient.create) r-> r.close
Copy link
Member

Choose a reason for hiding this comment

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

Why this line uses Managed _Resource and the line 24 is using...

Copy link
Member

Choose a reason for hiding this comment

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

Invoking a type looks like a coding mistake.

Google_Credential.From_File _ ->
betaAnalyticsDataSettings = BetaAnalyticsDataSettings.newBuilder
. setCredentialsProvider credentials.as_java
. build
BetaAnalyticsDataClient.create betaAnalyticsDataSettings
Managed_Resource.register (BetaAnalyticsDataClient.create betaAnalyticsDataSettings) r-> r.close
Copy link
Member

Choose a reason for hiding this comment

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

...this line is using Managed_Resource.register while line 19 only Managed_Resource.

@mergify mergify bot merged commit 59379ea into develop Apr 3, 2024
42 of 43 checks passed
@mergify mergify bot deleted the wip/hubert/google-analytics-close-resources branch April 3, 2024 13:33
hubertp added a commit that referenced this pull request Apr 4, 2024
Typo discovered post-PR review.
@hubertp hubertp mentioned this pull request Apr 4, 2024
mergify bot pushed a commit that referenced this pull request Apr 4, 2024
4e6 pushed a commit that referenced this pull request Apr 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI: No changelog needed Do not require a changelog entry for this PR. CI: Ready to merge This PR is eligible for automatic merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants