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

PubSub.close throws error #937

Closed
mad-it opened this issue Mar 31, 2020 · 12 comments · Fixed by #941
Closed

PubSub.close throws error #937

mad-it opened this issue Mar 31, 2020 · 12 comments · Fixed by #941
Assignees
Labels
api: pubsub Issues related to the googleapis/nodejs-pubsub API. priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@mad-it
Copy link

mad-it commented Mar 31, 2020

This bug report is related to #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)
@stephenplusplus stephenplusplus added priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels Mar 31, 2020
@stephenplusplus
Copy link
Contributor

// @feywind

@feywind
Copy link
Collaborator

feywind commented Mar 31, 2020

@mad-it @stephenplusplus Thanks! I will take a look in a moment.

@feywind
Copy link
Collaborator

feywind commented Apr 1, 2020

Well, this will teach me to not write a system test for a feature. :S The Pub/Sub client API objects are hand-written and not using a standard generated gax client, and this gets cast to a standard gax interface, which is really confusing. I'll work on getting this piped through tomorrow and add a system test based on the case above.

Thanks again for the report!

@yoshi-automation yoshi-automation added 🚨 This issue needs some love. and removed 🚨 This issue needs some love. labels Apr 6, 2020
@feywind
Copy link
Collaborator

feywind commented Apr 6, 2020

I'm not sure I like the issue auto-close. Anyway, this PR should fix the problem, can you try again?
#941

Specifically the recently released 1.7.1 should contain it.

@feywind feywind reopened this Apr 6, 2020
@product-auto-label product-auto-label bot added the api: pubsub Issues related to the googleapis/nodejs-pubsub API. label Apr 6, 2020
@merlinnot
Copy link
Contributor

@feywind Were you able to run it yourself? I just tried, made sure I have the latest version, but I still see the same error.

@mad-it
Copy link
Author

mad-it commented 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();
});

@merlinnot
Copy link
Contributor

Indeed. It looks like PublisherClient has the close method, but SubscriberClient does not.

@feywind
Copy link
Collaborator

feywind commented Apr 8, 2020

Hmm, that's interesting - the subscriber version was already there before my work on the publisher, so I didn't spend much time with it. It's possible that there was some code rot in there from the underlying gapic generation, too. I'll take a look at that.

@feywind
Copy link
Collaborator

feywind commented 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. :)

@merlinnot
Copy link
Contributor

Thanks for fixing it so quickly. It doesn't crash now, but it also doesn't seem to close gRPC connections. I'll try to create a minimal reproduction and report it in a separate issue, this one can be considered closed.

@merlinnot
Copy link
Contributor

My bad, it works perfectly fine. Thank you! 🎉

@mad-it
Copy link
Author

mad-it commented Apr 9, 2020

Thanks for the quick fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: pubsub Issues related to the googleapis/nodejs-pubsub API. priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants