sindresorhus / p-queue

Promise queue with concurrency control
MIT License
3.45k stars 185 forks source link

add() function doesnt do anything after extended use #110

Open blackchineykh opened 4 years ago

blackchineykh commented 4 years ago

Hi,

Ive been trying to use this solution in typescript and I instantiate multiple instances of the PQueue class for different job types.

After my nodejs app is run for an extended time, I notice that attempts to add to the queue do nothing.

    const { default: PQueue } = require("p-queue");
    const queue1 = new PQueue({ concurrency: 1 });
    const queue2 = new PQueue({ concurrency: 3 });

    public async queueComment(comment) {
      log.debug(`${comment.sender} queuing incoming comment...`);
      queue1.add(() => this.processComment(comment), this);
    }

    public async queueMessage(message) {
      log.debug(`${message.sender} queuing incoming message...`);
      queue2.add(() => this.processMessage(message), this);
    }

The queues are defined within a typescript class which is then instantiated and used to call the public functions to queue the comment and message received. After long running, the processComment and processMessage methods stopped getting called.

I'm wondering if something is causing the queue to stop, or if I can declare multiple queues in the same file or doing something else wrong thats causing this issue. Note that I also subscribe to the 'active' event which logs the size and pending in the queue, which also stops logging. It just seems the add() method on the queue just doesnt work anymore unless I restart. Note that this is also being run in a docker container.

Any directions are much appreciated as I rather not try to write my own handling of this logic

nylen commented 4 years ago

I haven't had any issues with this library during long-running usage, and multiple queues in the same file isn't a problem either.

Is it possible that your processComment and processMessage methods are hanging (never returning) sometimes?

You can try logging when these methods start and when they end (at all possible exit points). The count of "method start" log messages should be equal to the count of "method end" log messages.

kceb commented 4 years ago

I am also experiencing this but I am only instantiating once. It doesn't seem like the processComment and processMessage (in OP's example) would cause the issue because for both of us, the issue is resolved with a restart of the instance.

Also I have logs in the start of my process functions that don't seem to ever run.

kceb commented 4 years ago

@blackchineykh did you find a solution?

blackchineykh commented 1 week ago

@blackchineykh did you find a solution?

I never did. It doesn't seem consistent

YaminZheng commented 1 week ago

你应该有异步的函数被挂起了,一直没有返回,导致队列没有执行 你应该检查 队列的大小 有没有变化,来判断是否 add 成功 并给每一个异步函数设置超时时间

blackchineykh commented 1 week ago

你应该有异步的函数被挂起了,一直没有返回,导致队列没有执行 你应该检查 队列的大小 有没有变化,来判断是否 add 成功 并给每一个异步函数设置超时时间

Thanks. I'll check for that situation