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

Abort outstanding HTTP requests when subscription is closed #1104

Closed
ghost opened this issue Feb 3, 2016 · 4 comments · Fixed by #1070
Closed

Abort outstanding HTTP requests when subscription is closed #1104

ghost opened this issue Feb 3, 2016 · 4 comments · Fixed by #1070
Labels
api: pubsub Issues related to the Pub/Sub API. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@ghost
Copy link

ghost commented Feb 3, 2016

Hi!

After a certain event I just want my app to shut down. It seems, though, that gcloud (where I only use pubsub) keeps my App alive. Is there a way to kill pubsub so my App can shut down?

@stephenplusplus
Copy link
Contributor

It is probably a subscription object that is still pulling for new messages. You can quickly stop that process by calling subscription.removeAllListeners()

@ghost
Copy link
Author

ghost commented Feb 3, 2016

Hey @stephenplusplus, thanks for your answer.
That did not work for me.
Here a little example of what I mean. This will stay alive:

  let pubsub = gcloud.pubsub({
    projectId: projectId,
    keyFilename: keyPath
  });

  let topic = pubsub.topic('someTopic');

  topic.subscribe('update', function (error, sub) {
    if (error) {
      return console.log(error);
    }

    sub.on('error', function (error) {
      console.log(error);
    });

    sub.on('message', function (message) {
      console.log(message);
    });

    setTimeout(function () {
      sub.removeAllListeners();
    }, 500);
  });

@stephenplusplus
Copy link
Contributor

Got to the bottom of this! Unfortunately, there are a few pieces involved...

  1. Removing listeners is the right way to do this 👍, but our code doesn't abort the HTTP request that remains open while waiting for new messages. PR sent: pubsub: allow aborting an active HTTP request + auto-abort when subsc… #1105
  2. We need a way to abort requests, but we're limited by one of the libraries we use, retry-request. I just fixed that: googleapis/retry-request@ecb30d0
  3. We need a way for the underlying library, request to allow us to abort a request that has a timeout set. PR sent for that here: Cancel timeout on aborted requests request/request#2052

@stephenplusplus stephenplusplus added type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. api: pubsub Issues related to the Pub/Sub API. labels Feb 3, 2016
@stephenplusplus stephenplusplus changed the title How do I stop PubSub? Abort outstanding HTTP requests when subscription is closed Feb 5, 2016
@stephenplusplus
Copy link
Contributor

This is actually going to be resolved by #1070, since we're switching to using gRPC. If all goes well, a release that has this completely resolved will be put out on Monday.

sofisl pushed a commit that referenced this issue Nov 11, 2022
* fix: make `generate_index_ts()` deterministic (#1104)

Fixes googleapis/synthtool#1103
Source-Link: googleapis/synthtool@c3e41da
Post-Processor: gcr.io/repo-automation-bots/owlbot-nodejs:latest@sha256:e37a815333a6f3e14d8532efe90cba8aa0d34210f8c0fdbdd9e6a34dcbe51e96

* fix: regular expression matches v1, v1beta1 in order

* 🦉 Updates from OwlBot

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
Co-authored-by: Jeffrey Rennie <rennie@google.com>
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 Pub/Sub API. 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.

1 participant