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

Subscription is not automatically listening for new messages #1658

Closed
wagnerww opened this issue Nov 18, 2022 · 8 comments
Closed

Subscription is not automatically listening for new messages #1658

wagnerww opened this issue Nov 18, 2022 · 8 comments
Assignees
Labels
api: pubsub Issues related to the googleapis/nodejs-pubsub API. priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@wagnerww
Copy link

Thanks for stopping by to ask us a question! Please make sure to include:

  • What you're trying to do:
    I'm trying to read a subscription. However, when starting the process it receives some messages that are already published and after it is "idle", stopped, doing nothing. Wouldn't that be similar to Go or Java, where it runs and listens for messages being posted?

  • What code you've already tried:

     const pubSubClient = new PubSub();
     const subscription = pubSubClient.subscription("my-sub");
     
     subscription.on('message', (message) => {
        /// process
        message.ack();
    });
    
    subscription.on('error', logger.log);
    
  • Any error messages you're getting:
    I don't get an error, but I had to write this code below to let my CLI/Batch application listen for messages....but it doesn't seem like a good solution :(

       const pubSubClient = new PubSub();
    
       const listenSub =  () => {
           const subscription = pubSubClient.subscription("my-sub");
           
           subscription.on('message', (message) => {
              /// process
              message.ack();
          });
          
          subscription.on('error', logger.log);
            
            setTimeout(() => {
              subscription.removeListener('message', messageHandler);
              subscription.removeListener('error', logger.log);
             
              logger.log(`Messagens recebidas: ${messageCount}`);
              
             return listenSub();
            }, timeout);
        }
    
        listenSub()
    

PLEASE READ: If you have a support contract with Google, please create an issue in the support console instead of filing on GitHub. This will ensure a timely response.

@wagnerww wagnerww added priority: p3 Desirable enhancement or fix. May not be included in next release. type: question Request for information or clarification. Not an issue. labels Nov 18, 2022
@product-auto-label product-auto-label bot added the api: pubsub Issues related to the googleapis/nodejs-pubsub API. label Nov 18, 2022
@brianofrokk3r
Copy link

brianofrokk3r commented Nov 28, 2022

I believe I am having similar/same issue.

Getting about 50-75 messages on the subscription, then the connection goes idle. Tried both ack, and ackWithResponse.

Meanwhile, the topic still contains > 1000 unacked messages.

When I restart the subscription, it gets another 50-75 messages, and does the same thing. I am using the default topic and subscription configuration with an extended acknowledgement deadline.

@brianofrokk3r
Copy link

@wagnerww

Using flowControl within subscriber options (see example), I was able to process any number of messages over a longer period of time. This seemed to resolve my specific issue. Using this in combination with your connection restart as per the example increases overall stability.

// configure options
    const subscriptionName = "SomeSubscription";
    const maxInProgress = 5; // 1-3 worked well for me, 5 started hanging occasionally
    const subscriberOptions = {
        flowControl: {
          maxMessages: maxInProgress,
        },
      };

//create subscription
const subscription = pubsub.subscription(subscriptionName, subscriberOptions);

// on message do something
subscription.on('message', (message) => {
      // messagehandler acks message
      messageHandler(message)
});

@feywind
Copy link
Collaborator

feywind commented Dec 16, 2022

Hmm, I wonder if (like #1665) the acks don't seem to be going through. The server side itself does some flow control, and it would probably stop delivering messages if it's not receiving acks, which does seem to line up with the delivery behaviour.

If either of you have a support contract, it might be useful to have someone look at what's happening on the back end.

Out of curiosity, do either of you see the same issue if you go back to 3.0.x? I'm trying to figure out if there was a library regression during the exactly once delivery updates.

@himkwtn
Copy link

himkwtn commented Jan 19, 2023

We are also facing the same issue where the subscriber client randomly stop pulling in new messages.

Environment

  • docker image: node:16.18.1-bullseye-slim
  • pubsub client version 3.1.0
  • default flow control options
  • messageOrdering enabled

What is weird is that not all subscriptions are facing this problem and some subscriptions stop more often than other.
Sometimes the subscription can recover itself for a few minutes and then goes idle.
This also rarely happened in the past but these past week it has been happening very often.

Right now we have to manually restart our backend application which is not ideal at all.


Examples

Subscription 1
Screen Shot 2566-01-19 at 16 03 08
Subscription 2
Screen Shot 2566-01-19 at 16 09 18

@regevbr
Copy link

regevbr commented Apr 12, 2023

same issue here

@panoc1
Copy link

panoc1 commented May 29, 2023

Any updates on this? We are hitting the same issue here

@kamalaboulhosn kamalaboulhosn added priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. and removed type: question Request for information or clarification. Not an issue. priority: p3 Desirable enhancement or fix. May not be included in next release. labels Jun 20, 2023
@iamcrisb
Copy link

updates?

@feywind
Copy link
Collaborator

feywind commented Oct 16, 2023

In regards to subscriptions randomly stopping, that's a long term issue we've been looking for solutions for, and we might've found some recently in the latest 4.x branch updates, with grpc keepalives. If possible, try the 4.x branch (requires Node 14, but otherwise basically the same as 3.x), and if problems are still happening, please file a support ticket, as we will likely need to take a look at your specific config and logs.

@feywind feywind closed this as completed Oct 16, 2023
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: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

No branches or pull requests

8 participants