spring-attic / spring-cloud-gcp

Integration for Google Cloud Platform APIs with Spring
Apache License 2.0
704 stars 694 forks source link

ManagedChannel not properly closed #2581

Closed saturnism closed 3 years ago

saturnism commented 3 years ago

Describe the bug https://github.com/spring-cloud/spring-cloud-gcp/blob/master/spring-cloud-gcp-autoconfigure/src/main/java/org/springframework/cloud/gcp/autoconfigure/pubsub/GcpPubSubEmulatorAutoConfiguration.java#L48

The ManagedChannel here is not closed properly upon application context close, and may produce a warning:

i.g.i.ManagedChannelOrphanWrapper        : *~*~*~ Channel ManagedChannelImpl{logId=1, target=dns:///104.154.63.246:32819} was not shutdown properly!!! ~*~*~*
    Make sure to call shutdown()/shutdownNow() and wait until awaitTermination() returns true.

ManagedChannel should be produced as a bean w/ destroy method specified, so that Spring can shutdown/destroy the managed channel.

Sample https://github.com/saturnism/testcontainers-gcloud-examples/blob/main/springboot/pubsub-example/src/test/java/com/example/springboot/pubsub/PubSubIntegrationTests.java

Run with mvn verify to run the integration test and observe the error.

meltsufin commented 3 years ago

I think the root cause is that the ManagedChannel is not a bean in GcpPubSubEmulatorAutoConfiguration.

meltsufin commented 3 years ago

@saturnism I've run your sample, but I'm not seeing the error.