Skip to content

pubsub will throw during Subscription.pull when autoAck is on and no messages avail #455

Description

@jaredrhine

I'm porting to v1beta2 of the pubsub service. In recent versions of gcloud-node, my previous code will abort in Subscription.pull with:

Error: At least one ID must be specified before it can be acknowledged.
    at Subscription.ack     (/Users/jared/work/other/deep/node_modules/gcloud/lib/pubsub/subscription.js:258:11)

I use autoAck and right now there are very few messages on the topic. So I think what's happening is the long-poll completes without receiving a message, and this block in Subscription.pull:

  this.makeReq_('POST', path, null, body, function(err, response) {
    if (err) {
      callback(err);
      return;
    }

    var messages = response.receivedMessages || [];
    messages = messages.map(Subscription.formatMessage_);

    if (self.autoAck) {
      var ackIds = messages.map(function(message) {
        return message.ackId;
      });

      self.ack(ackIds, function(err) {
        callback(err, messages);
      });

calls self.ack with ackIds empty because receivedMessages is empty. I fixed this in my local copy with:

if (self.autoAck && messages.length != 0) {

since there's no point in trying to ack if there are no messages. If I had a bit more time right now, I'd offer a PR with a test, but let's get an issue opened at least to see if the problem has been characterized correctly first.

Activity

  1. jaredrhine commented on Mar 21, 2015

    @jaredrhine
    Author

    Oh, I think the issue was caused in 1233ac6 during the 1beta2 API bump by @ryanseys (that you for that fix! I'd be dead in the water without that commit, and I'd encourage a 0.13.0 release to pick up those changes). The array always had at least one item in it previously, but now it can be empty.

  2. ryanseys commented on Mar 21, 2015

    @ryanseys
    Contributor

    To clarify, is this still a bug in master?

  3. ryanseys commented on Mar 21, 2015

    @ryanseys
    Contributor

    I realize we do need to release 0.13.0 soon. We've been wrestling with some regression tests for a while that have distracted from a next release. I hope to have something out soon.

  4. jaredrhine commented on Mar 22, 2015

    @jaredrhine
    Author

    Yes, the behavior described (throw+exit) happens on gcloud-node master as of today, and the code snippets in comment 1 are from master. Thanks!

  5. ryanseys commented on Mar 22, 2015

    @ryanseys
    Contributor

    Yep totally makes sense, I'll get a fix out for this.

  6. ryanseys commented on Mar 22, 2015

    @ryanseys
    Contributor

    Fix, as you suggested, in #456.

  7. added
    type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.
    api: pubsubIssues related to the Pub/Sub API.
    on May 14, 2015
  8. added this to the Pub/Sub Beta milestone on May 14, 2015
  9. added a commit that references this issue on Sep 15, 2022
  10. 28 remaining items

  11. added a commit that references this issue on Feb 26, 2026
  12. added a commit that references this issue on Mar 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

🚨This issue needs some love.api: pubsubIssues related to the Pub/Sub API.triage meI really want to be triaged.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions