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

docs: close Spanner instance when it is no longer needed #1116

merged 1 commit into from May 3, 2021


Copy link

@olavloite olavloite commented Apr 30, 2021

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,} 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>(
	at io.grpc.internal.ManagedChannelOrphanWrapper.<init>(
	at io.grpc.internal.ManagedChannelOrphanWrapper.<init>(
	at com.example.spanner.CreateInstanceExample.createInstance(
	at com.example.spanner.SpannerSampleIT.lambda$testCreateInstanceSample$0(
	at com.example.spanner.SpannerSampleIT.runSampleRunnable(
	at com.example.spanner.SpannerSampleIT.testCreateInstanceSample(
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(
	at java.lang.reflect.Method.invoke(
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(
	at org.junit.runners.ParentRunner$3.evaluate(
	at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(
	at org.junit.runners.ParentRunner.runLeaf(
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(
	at org.junit.runners.ParentRunner$
	at org.junit.runners.ParentRunner$1.schedule(
	at org.junit.runners.ParentRunner.runChildren(
	at org.junit.runners.ParentRunner.access$100(
	at org.junit.runners.ParentRunner$2.evaluate(
	at org.junit.internal.runners.statements.RunBefores.evaluate(
	at org.junit.internal.runners.statements.RunAfters.evaluate(
	at org.junit.runners.ParentRunner$3.evaluate(
	at org.apache.maven.surefire.junit4.JUnit4Provider.execute(
	at org.apache.maven.surefire.junit4.JUnit4Provider.executeWithRerun(
	at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(
	at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(
	at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(
	at org.apache.maven.surefire.booter.ForkedBooter.execute(
	at org.apache.maven.surefire.booter.ForkedBooter.main(

(See for example

The CreateInstance example opened a Spanner instance without closing it.
That was spamming the test logs with a lot of warnings.
@olavloite olavloite requested a review from thiagotnunes Apr 30, 2021
@olavloite olavloite requested a review from as a code owner Apr 30, 2021
@olavloite olavloite requested a review from Apr 30, 2021
@product-auto-label product-auto-label bot added the api: spanner label Apr 30, 2021
@google-cla google-cla bot added the cla: yes label Apr 30, 2021
Copy link

@codecov codecov bot commented Apr 30, 2021

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 Files Coverage Δ Complexity Δ
...m/google/cloud/spanner/connection/ 87.16% <0.00%> (-0.54%) 33.00% <0.00%> (ø%)
...ain/java/com/google/cloud/spanner/ 89.01% <0.00%> (ø) 74.00% <0.00%> (-1.00%)
...a/com/google/cloud/spanner/ 69.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.

lesv approved these changes Apr 30, 2021
@@ -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 {
Copy link

@lesv lesv Apr 30, 2021

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
Contributor Author

@olavloite olavloite May 3, 2021

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.

@olavloite olavloite merged commit 85bd0cf into master May 3, 2021
17 of 18 checks passed
@olavloite olavloite deleted the create-instance-example-close-spanner branch May 3, 2021
gcf-merge-on-green bot pushed a commit that referenced this issue May 13, 2021
🤖 I have created a release \*beep\* \*boop\*
### [6.4.1]( (2021-05-13)

### Documentation

* close Spanner instance when it is no longer needed ([#1116]( ([85bd0cf](

### Dependencies

* update dependency to v2.2.2 ([#1158]( ([63eed2e](
* update dependency to v1.1.0 ([#1152]( ([2e7f18a](
* update dependency org.openjdk.jmh:jmh-core to v1.30 ([#1137]( ([699a426](
* update dependency org.openjdk.jmh:jmh-core to v1.31 ([#1160]( ([43a0fb9](
* update dependency org.openjdk.jmh:jmh-generator-annprocess to v1.30 ([#1138]( ([ad6649d](
* update dependency org.openjdk.jmh:jmh-generator-annprocess to v1.31 ([#1161]( ([4d17da2](

This PR was generated with [Release Please]( See [documentation](
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
api: spanner cla: yes
None yet

Successfully merging this pull request may close these issues.

None yet

3 participants