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

Unhandled promise in message.ack() makes it hard for a terminating script to wait for ack #1221

Closed
everhardt opened this issue Mar 3, 2021 · 2 comments
Labels
api: pubsub Issues related to the googleapis/nodejs-pubsub API. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.

Comments

@everhardt
Copy link

Environment details

  • @google-cloud/pubsub version: 2.10.0

Steps to reproduce

const pubsub = new PubSub();
const subscription = pubsub.subscription(subscriptionName);
subscription.on('message', (m: Message) => {
  const dataUtf8encoded = m.data.toString('utf8');
  let event: unknown;
  try {
    event = JSON.parse(dataUtf8encoded);
  } catch (ex) {
    m.ack();
    console.log('Fail!');
    // ISSUE: the process will exit before the ack has been sent
    process.exit(1);
  }
  doSomethingWith(event);
  m.ack();
});

See the comment line starting with // ISSUE: in the code above. An unexpected message will in this case not be cleared from the subscription. If my process would restart automatically, it would be in an infinite loop now. The problem is that m.ack() does not return a promise (while the underlying subscriber ack function does). That seems to be a problem for others as well, see:

I read in #428:

Unfortunately this isn't the first time this request has been made, but we've had some push back from the PubSub API team in the past.

I cannot find that push back discussion. If there's a good reason not to return a promise, an alternative would be to make _waitForFlush a public method. That I can await that before exiting the process.

ps. I can of course set an arbitrary timeout before exiting the process, but that's ugly.

@product-auto-label product-auto-label bot added the api: pubsub Issues related to the googleapis/nodejs-pubsub API. label Mar 3, 2021
@yoshi-automation yoshi-automation added triage me I really want to be triaged. 🚨 This issue needs some love. labels Mar 4, 2021
@ettancos
Copy link

ettancos commented Mar 12, 2021

I would like an option to flush the acks for graceful shutdown and to be able to see a trace if there is a rejection there. Recently we run into the situation where we had to debug some occasional unhandled promise rejections, and we had to patch the ack/nack functions to use the underlying functions to be able to rule it out as the source.

@meredithslota meredithslota added type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. and removed 🚨 This issue needs some love. triage me I really want to be triaged. labels Mar 12, 2021
@feywind
Copy link
Collaborator

feywind commented Mar 24, 2022

That's pretty gross, yeah. I feel like this is probably related to this, work wise:

#725

I'm going to add this issue to the internal backlog for that work.

@feywind feywind closed this as completed Mar 24, 2022
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. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.
Projects
None yet
Development

No branches or pull requests

5 participants