Promise.allSettled stuck forever

I use Promise.allSettled to fetch websites in batch fashion. It works fine if I limit size of website list to 10 but it become stuck as soon as I increase it to 1000.

This is weird and never happened to me. I’ve waited for three days until the script finish but it’s still stuck at the first 1000 items.

const rp = require('request-promise');
const lineReader = require('line-by-line');

const reader = new lineReader("./all.json");

let lines = [];
const limit = 1000;

let successCount = 0;

reader.on('line', async (line) => {
    line = JSON.parse(line);


    if (lines.length === limit) {

        let promises = [];

        for (const line of lines) {
        await Promise.allSettled(promises);

        console.log(`Success Count is ${successCount}`);

        lines = [];


The data.json file has website list under following format,

{ website: "" }
{ website: "" }
{ website: "" }

You can reproduce the behavior by duplicating a line like { website: "" } 2000 times.


The solution is to wrap up my promise with a promise that timeout after certain period.

Here is the function that provides the ability timeout the promise,

const withTimeout = (millis, promise) => {
    const timeout = new Promise((resolve, reject) =>
            () => reject(`Timed out after ${millis} ms.`),
    return Promise.race([

You can use it like below,

await Promise.allSettled([
   withTimeout(5000, rp(""),
   withTimeout(5000, rp(""),

I know you can specify a timeout in the request-promise options, but for some reason it didn’t work for me, but I noticed certain improvements when I added it.