-
-
Notifications
You must be signed in to change notification settings - Fork 195
Open
Description
At the moment I'm testing my project and I run into following error
Exception in PromiseRejectCallback:
file:///MY_PROJECT/node_modules/p-queue/dist/index.js:202
}, options);
^
RangeError: Maximum call stack size exceeded
I add 10,000 tasks and after some seconds I abort all 10,000 tasks and remove them. Then I get the RangeError
.
If I look into the code, could it be that there is a recursion (in the case when many tasks have been aborted)?
If I see it correctly, then #next()
calls tryToStartAnother()
and tryToStartAnother()
calls job()
and job()
has a try-catch block which calls #next()
in the finally block.
#next(): void {
...
this.#tryToStartAnother();
...
}
#tryToStartAnother(): boolean {
...
if (!this.#isPaused) {
...
job();
...
}
...
}
async add<TaskResultType>(...): ... {
...
return new Promise((resolve, reject) => {
this.#queue.enqueue(async () => {
...
try {
...
} catch (error: unknown) {
...
} finally {
this.#next();
}
}, options);
...
}
Following code demonstrates my issue
import PQueue from 'p-queue';
console.log('Start');
const queue = new PQueue({concurrency: 1});
const controller = new AbortController();
for (let i = 0; i < 10000; i++) {
queue.add(() => { 1 + 1 }, { signal: controller.signal });
}
console.log('Abort');
controller.abort();
// wait for 10 seconds
await new Promise(resolve => setTimeout(resolve, 10000));
console.log('Done waiting');
Metadata
Metadata
Assignees
Labels
No labels