Conversation

olavloite

The CreateInstance example opened a Spanner instance without closing it. That was spamming the test logs with a lot of the following warnings:

Apr 29, 2021 8:06:34 AM io.grpc.internal.ManagedChannelOrphanWrapper$ManagedChannelReference cleanQueue
SEVERE: *~*~*~ Channel ManagedChannelImpl{logId=191, target=spanner.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:93)
	at io.grpc.internal.ManagedChannelOrphanWrapper.<init>(ManagedChannelOrphanWrapper.java:53)
	at io.grpc.internal.ManagedChannelOrphanWrapper.<init>(ManagedChannelOrphanWrapper.java:44)
	at io.grpc.internal.ManagedChannelImplBuilder.build(ManagedChannelImplBuilder.java:615)
	at io.grpc.internal.AbstractManagedChannelImplBuilder.build(AbstractManagedChannelImplBuilder.java:261)
	at com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.createSingleChannel(InstantiatingGrpcChannelProvider.java:327)
	at com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.access$1700(InstantiatingGrpcChannelProvider.java:74)
	at com.google.api.gax.grpc.InstantiatingGrpcChannelProvider$1.createSingleChannel(InstantiatingGrpcChannelProvider.java:220)
	at com.google.api.gax.grpc.ChannelPool.create(ChannelPool.java:72)
	at com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.createChannel(InstantiatingGrpcChannelProvider.java:227)
	at com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.getTransportChannel(InstantiatingGrpcChannelProvider.java:210)
	at com.google.api.gax.rpc.ClientContext.create(ClientContext.java:169)
	at com.google.cloud.spanner.admin.database.v1.stub.GrpcDatabaseAdminStub.create(GrpcDatabaseAdminStub.java:289)
	at com.google.cloud.spanner.spi.v1.GapicSpannerRpc.<init>(GapicSpannerRpc.java:483)
	at com.google.cloud.spanner.SpannerOptions$DefaultSpannerRpcFactory.create(SpannerOptions.java:465)
	at com.google.cloud.spanner.SpannerOptions$DefaultSpannerRpcFactory.create(SpannerOptions.java:460)
	at com.google.cloud.ServiceOptions.getRpc(ServiceOptions.java:560)
	at com.google.cloud.spanner.SpannerOptions.getSpannerRpcV1(SpannerOptions.java:1168)
	at com.google.cloud.spanner.SpannerImpl.<init>(SpannerImpl.java:135)
	at com.google.cloud.spanner.SpannerOptions$DefaultSpannerFactory.create(SpannerOptions.java:455)
	at com.google.cloud.spanner.SpannerOptions$DefaultSpannerFactory.create(SpannerOptions.java:450)
	at com.google.cloud.ServiceOptions.getService(ServiceOptions.java:540)
	at com.example.spanner.CreateInstanceExample.createInstance(CreateInstanceExample.java:41)
	at com.example.spanner.SpannerSampleIT.lambda$testCreateInstanceSample$0(SpannerSampleIT.java:405)
	at com.example.spanner.SpannerSampleIT.runSampleRunnable(SpannerSampleIT.java:394)
	at com.example.spanner.SpannerSampleIT.testCreateInstanceSample(SpannerSampleIT.java:403)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
	at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
	at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
	at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
	at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
	at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:364)
	at org.apache.maven.surefire.junit4.JUnit4Provider.executeWithRerun(JUnit4Provider.java:272)
	at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:237)
	at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:158)
	at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:428)
	at org.apache.maven.surefire.booter.ForkedBooter.execute(ForkedBooter.java:162)
	at org.apache.maven.surefire.booter.ForkedBooter.run(ForkedBooter.java:562)
	at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:548)

(See for example https://source.cloud.google.com/results/invocations/983ec088-8806-4576-8f9c-640be588a836/targets/cloud-devrel%2Fclient-libraries%2Fjava%2Fjava-spanner%2Fnightly%2Fjava8-samples/log)

The CreateInstance example opened a Spanner instance without closing it.
That was spamming the test logs with a lot of warnings.
@olavloiteolavloite requested a review from a team as a code owner April 30, 2021 13:24
@olavloiteolavloite requested a review from a team April 30, 2021 13:24
@product-auto-labelproduct-auto-label bot added the api: spannerIssues related to the googleapis/java-spanner API.label Apr 30, 2021
@google-clagoogle-cla bot added the cla: yesThis human has signed the Contributor License Agreement.label Apr 30, 2021
@codecov

Codecov Report

Merging #1116 (3c6b1ee) into master (7001030) will decrease coverage by 0.00%.
The diff coverage is n/a.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #1116      +/-   ##
============================================
- Coverage     84.98%   84.97%   -0.01%     
+ Complexity     2727     2724       -3     
============================================
  Files           156      156              
  Lines         14416    14416              
  Branches       1381     1381              
============================================
- Hits          12251    12250       -1     
- Misses         1594     1597       +3     
+ Partials        571      569       -2     
Impacted FilesCoverage ΔComplexity Δ
...m/google/cloud/spanner/connection/SpannerPool.java87.16% <0.00%> (-0.54%)33.00% <0.00%> (ø%)
...ain/java/com/google/cloud/spanner/SessionPool.java89.01% <0.00%> (ø)74.00% <0.00%> (-1.00%)
...a/com/google/cloud/spanner/SessionPoolOptions.java69.53% <0.00%> (ø)17.00% <0.00%> (-1.00%)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7001030...3c6b1ee. Read the comment docs.

@@ -65,6 +65,8 @@ static void createInstance(String projectId, String instanceId) {
instanceInfo.getId(), e.getMessage());
} catch (InterruptedException e) {
System.out.println("Error: Waiting for createInstance operation to finish was interrupted");
} finally {
spanner.close();
Copy link
Contributor

Choose a reason for hiding this comment

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

I presume your not using try-with-resources syntax because users are likely to keep spanner open across methods. If so, LGTM, if not, consider using try (spanner = ...) { ... } syntax.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Correct, a Spanner instance should preferably be kept open during the entire lifetime of the application, so we don't want to 'encourage' quickly opening and closing a Spanner instance.

@olavloiteolavloite merged commit 85bd0cf into master May 3, 2021
@olavloiteolavloite deleted the create-instance-example-close-spanner branch May 3, 2021 06:46
gcf-merge-on-green bot pushed a commit that referenced this pull request May 13, 2021
🤖 I have created a release \*beep\* \*boop\*
---
### [6.4.1](https://www..com/googleapis/java-spanner/compare/v6.4.0...v6.4.1) (2021-05-13)


### Documentation

* close Spanner instance when it is no longer needed ([#1116](https://www..com/googleapis/java-spanner/issues/1116)) ([85bd0cf](https://www..com/googleapis/java-spanner/commit/85bd0cf11eab7b2ec47a082a4c2c0c4d9cea01d4))


### Dependencies

* update dependency com.google.cloud:google-cloud-monitoring to v2.2.2 ([#1158](https://www..com/googleapis/java-spanner/issues/1158)) ([63eed2e](https://www..com/googleapis/java-spanner/commit/63eed2e66fb063358e8b123ba5f919663b70bbe4))
* update dependency com.google.cloud:google-cloud-shared-dependencies to v1.1.0 ([#1152](https://www..com/googleapis/java-spanner/issues/1152)) ([2e7f18a](https://www..com/googleapis/java-spanner/commit/2e7f18a52ef2ed5de6a87169eeefd570844a4c55))
* update dependency org.openjdk.jmh:jmh-core to v1.30 ([#1137](https://www..com/googleapis/java-spanner/issues/1137)) ([699a426](https://www..com/googleapis/java-spanner/commit/699a4260e3b1a4cf53fc690910aeeadac293e469))
* update dependency org.openjdk.jmh:jmh-core to v1.31 ([#1160](https://www..com/googleapis/java-spanner/issues/1160)) ([43a0fb9](https://www..com/googleapis/java-spanner/commit/43a0fb97352d928e16ec5138ed2ea494ebaae343))
* update dependency org.openjdk.jmh:jmh-generator-annprocess to v1.30 ([#1138](https://www..com/googleapis/java-spanner/issues/1138)) ([ad6649d](https://www..com/googleapis/java-spanner/commit/ad6649df03a1a193dd524a84fe9dc1a72ed14e09))
* update dependency org.openjdk.jmh:jmh-generator-annprocess to v1.31 ([#1161](https://www..com/googleapis/java-spanner/issues/1161)) ([4d17da2](https://www..com/googleapis/java-spanner/commit/4d17da25977dde0cc1032192045d9ee26d3fae09))
---


This PR was generated with [Release Please](https://.com/googleapis/release-please). See [documentation](https://.com/googleapis/release-please#release-please).
Sign up for free to join this conversation on . Already have an account? Sign in to comment
api: spannerIssues related to the googleapis/java-spanner API.cla: yesThis human has signed the Contributor License Agreement.
None yet

Successfully merging this pull request may close these issues.