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.

PubSub.close throws error

See original GitHub issue

This bug report is related to https://github.com/googleapis/nodejs-pubsub/pull/916.

Environment details

  • OS: Linux
  • Node.js version: v10.16.3
  • npm version: 6.9.0
  • @google-cloud/pubsub version: 1.7.0

Steps to reproduce

Here is a test written to test this newly introduced close method.

import { PubSub } from '@google-cloud/pubsub';

it('test pubsub close', async (): Promise<void> => {
  expect.assertions(1);
  const topicName = 'test-topic';

  const pubSub = new PubSub();

  const [topic] = await pubSub.topic(topicName).get({ autoCreate: true });

  await topic.publish(Buffer.from('test-message'));

  expect(await pubSub.topic(topicName).exists()).toStrictEqual([true]);

  await pubSub.close();
});

When running this simple test in Jest, I get the following error.

 FAIL  src/test.spec.ts (7.801s)
  ✕ test pubsub close (106ms)

  ● test pubsub close

    TypeError: gaxClient.close is not a function

      13 |   expect(await pubSub.topic(topicName).exists()).toStrictEqual([true]);
      14 | 
    > 15 |   await pubSub.close();
         |                ^
      16 | });
      17 | 

      at PubSub.closeAllClients_ (node_modules/@google-cloud/pubsub/src/pubsub.ts:983:31)
      at PubSub.close (node_modules/@google-cloud/pubsub/src/pubsub.ts:302:12)
      at PromiseCtor (node_modules/@google-cloud/promisify/build/src/index.js:69:28)
      at PubSub.wrapper (node_modules/@google-cloud/promisify/build/src/index.js:54:16)
      at Object.it (src/test.spec.ts:15:16)

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:12 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
feywindcommented, Apr 9, 2020

@merlinnot @mad-it 1.7.2 adds the close() method to the SubscriberClient also. Let me know if that works for you? I think that should be all of them, since there are only stubs for publisher and subscriber. There is another system-test that will validate that this one works going forward as well.

We’re in the process of releasing 2.0.0 that will bring a lot of dependencies up to date, and also introduce TypeScript generated service stubs that have a close() method built in. I wanted to backport this to the existing 1.x branch though… it doesn’t seem like a good idea to require a major version update for a bug fix. 😃

1reaction
mad-itcommented, Apr 7, 2020

@feywind it looks like this issue has been resolved for the very specific test case provided, but the same issue occurs when a subscriber is created.

By adding await topic.subscription('subscriber-1').get({ autoCreate: true }); to the test case above we get the exact same error.

So the complete test case becomes:

import { PubSub } from '@google-cloud/pubsub';

it('test pubsub close', async (): Promise<void> => {
  expect.assertions(1);

  const topicName = 'test-topic';

  const pubSub = new PubSub();

  const [topic] = await pubSub.topic(topicName).get({ autoCreate: true });

  await topic.subscription('subscriber-1').get({ autoCreate: true });

  await topic.publish(Buffer.from('test-message'));

  expect(await pubSub.topic(topicName).exists()).toStrictEqual([true]);

  await pubSub.close();
});
Read more comments on GitHub >

github_iconTop Results From Across the Web

PubSub - Error message on subscription.close() #5096 - GitHub
... closing a subscription, the following message is printed to stderr but no exception is thrown: ERROR:root:Exception serializing message!
Read more >
Troubleshooting | Cloud Pub/Sub Documentation
Learn about troubleshooting steps that you might find helpful if you run into problems using Pub/Sub. Cannot create a subscription.
Read more >
Google Cloud Pub/Sub error "Closed subscriber cannot be ...
Well, Google's own documentation states that the code I was using would automatically close the subscription because of the with block.
Read more >
Enricher ERROR com.google.cloud.pubsub.v1 ...
Hello Everyone, I have been seeing a lot of these errors in enricher pod logs. ... and above probably because enricher is throwing...
Read more >
com.google.cloud.pubsub.v1.TopicAdminClient.close java ...
@AfterClass public static void afterClass() throws Exception { topicAdminClient.close(); if (notificationService != null) { boolean wasDeleted ...
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