question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Closing the PubSub client does not cleanup grpc connection

See original GitHub issue

Environment 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:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:13

github_iconTop GitHub Comments

1reaction
murgatroid99commented, Feb 12, 2021

I have published a new version of grpc-js that might help with this. Can you update your dependencies and try again?

0reactions
feywindcommented, Mar 16, 2021

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found