Closing the PubSub client does not cleanup grpc connection
See original GitHub issueEnvironment details
- OS: MacOS 11.1 (20C69)
- Node.js version: 14.15.3
- npm version: 6.14.9
@google-cloud/pubsub
version: 2.8.0
Steps to reproduce
I noticed the issue because jest complains about:
Jest did not exit one second after the test run has completed. This usually means that there are asynchronous operations that weren’t stopped in your tests. Consider running Jest with
--detectOpenHandles
to troubleshoot this issue.
But the issue can also be observed without a test runner:
import log from 'why-is-node-running'
import pubsub from '@google-cloud/pubsub';
(async () => {
const client1 = new pubsub.PubSub({
projectId: 'stub',
});
const [topic1] = await client1.createTopic('test');
await topic1.delete();
await client1.close();
log();
})();
Output:
There are 10 handle(s) keeping the process running
# DNSCHANNEL
(unknown stack trace)
# TTYWRAP
/Users/michael/www/node_modules/supports-color/index.js:129 - stdout: getSupportLevel(process.stdout),
# SIGNALWRAP
/Users/michael/www/node_modules/supports-color/index.js:129 - stdout: getSupportLevel(process.stdout),
# TTYWRAP
/Users/michael/www/node_modules/supports-color/index.js:130 - stderr: getSupportLevel(process.stderr)
# Timeout
/Users/michael/www/node_modules/@grpc/grpc-js/build/src/backoff-timeout.js:63 - this.timerId = setTimeout(() => {
/Users/michael/www/node_modules/@grpc/grpc-js/build/src/subchannel.js:189 - this.backoffTimeout.runOnce();
/Users/michael/www/node_modules/@grpc/grpc-js/build/src/subchannel.js:397 - this.startBackoff();
/Users/michael/www/node_modules/@grpc/grpc-js/build/src/subchannel.js:554 - if (!this.transitionToState([channel_1.ConnectivityState.IDLE], channel_1.ConnectivityState.CONNECTING)) {
# TCPWRAP
/Users/michael/www/node_modules/@grpc/grpc-js/build/src/subchannel.js:261 - return net.connect(this.subchannelAddress);
/Users/michael/www/node_modules/@grpc/grpc-js/build/src/subchannel.js:283 - const session = http2.connect(addressScheme + targetAuthority, connectionOptions);
/Users/michael/www/node_modules/@grpc/grpc-js/build/src/subchannel.js:361 - this.createSession(result);
# HTTP2SESSION
(unknown stack trace)
# Immediate
/Users/michael/www/node_modules/google-gax/build/src/call.js:70 - setImmediate(this.callback, ...args);
/Users/michael/www/node_modules/google-gax/build/src/normalCalls/retries.js:82 - callback(null, response, next, rawResponse);
/Users/michael/www/node_modules/@grpc/grpc-js/build/src/client.js:173 - callProperties.callback(null, responseMessage);
/Users/michael/www/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:334 - (_b = listener === null || listener === void 0 ? void 0 : listener.onReceiveStatus) === null || _b === void 0 ? void 0 : _b.call(listener, status);
# TickObject
(unknown stack trace)
# TickObject
/Users/michael/www/node_modules/@grpc/grpc-js/build/src/subchannel.js:411 - process.nextTick(() => {
/Users/michael/www/node_modules/@grpc/grpc-js/build/src/subchannel.js:441 - this.transitionToState([
/Users/michael/www/node_modules/@grpc/grpc-js/build/src/subchannel.js:496 - this.checkBothRefcounts();
/Users/michael/www/node_modules/@grpc/grpc-js/build/src/subchannel.js:500 - this.unref();
/Users/michael/www/node_modules/@grpc/grpc-js/build/src/subchannel-pool.js:56 - const refedSubchannels = subchannelObjArray.filter((value) => !value.subchannel.unrefIfOneRef());
while this works fine:
import log from 'why-is-node-running'
import pubsub from '@google-cloud/pubsub';
(async () => {
const client1 = new pubsub.PubSub({
projectId: 'stub',
});
/// nothing is done
await client1.close();
log();
})();
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:13
Top Results From Across the Web
Error Codes | Cloud Pub/Sub Documentation
Error HTTP Code Description
UNAUTHENTICATED 401 The client is not authenticated properly.
UNAVAILABLE 503 The service was unable to process a request.
Read more >Golang gRPC can't keep alive: the client connection is closing
Its because the defer conn.Close() command will be executed before the connection is even used. From the go blog.
Read more >gRPC on HTTP/2 Engineering a Robust, High-performance ...
When connections close cleanly, TCP semantics suffice: closing a connection causes the FIN handshake to occur. This ends the HTTP/2 connection, ...
Read more >Trouble-Shooting | grpc-spring-boot-starter - GitHub Pages
The server/client does not start because some class or method is missing. This is usually the case if the grpc-libraries use slightly different...
Read more >Things I wish I knew about Google Cloud Pub/Sub: Part 2
Client libraries that support streaming pull will establish a StreamingPull connection (over a gRPC stream). This is usually preferred over the ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I have published a new version of grpc-js that might help with this. Can you update your dependencies and try again?
It sounds like we can close this, then? This patch looks like it went into a recent
@grpc/grpc-js
release, so anyone having the problem should be able to pull in the newest version of that.Please feel free to ping if it needs reopening.