josdejong / workerpool

Offload tasks to a pool of workers on node.js and in the browser
Apache License 2.0
2.06k stars 147 forks source link

Error: TimeoutError: Promise timed out after 600000 milliseconds #380

Closed MarianoFacundoArch closed 1 year ago

MarianoFacundoArch commented 1 year ago

I don't have configured any timeout, still I get that error after that number. I cannot find that number anywhere in the code, and i cannot find where it's happening either.

josdejong commented 1 year ago

So what are you doing exactly? How to reproduce your issue?

MarianoFacundoArch commented 1 year ago

I have a promise that takes more than that amount of time.

        result = await jobsPool
          .exec("performExecutionOfSpecificJob", [
            jobToProcess._id.toString(),
            jobToProcess.client._id.toString(),
            JSON.stringify(configToProcess),
            jobToProcess.notificationsCallback,
          ])

That is the exact code. Thinking there might be some default, I even added the timeout line with a 120 minutes timeout but the error with the 600000 milliseconds still occur

        result = await jobsPool
          .exec("performExecutionOfSpecificJob", [
            jobToProcess._id.toString(),
            jobToProcess.client._id.toString(),
            JSON.stringify(configToProcess),
            jobToProcess.notificationsCallback,
          ])
          .timeout(configProvider.HARD_TIMEOUT_FOR_JOB_IN_MINUTES * 60 * 1000);
josdejong commented 1 year ago

I tried to reproduce your issue with the following minimal example, running the script for more than 10 minutes, but the error does not occur:

const workerpool = require('workerpool');
const pool = workerpool.pool();

// Test issue https://github.com/josdejong/workerpool/issues/380

function testTimeout() {
  return new Promise(resolve => {
    setTimeout(() => {
      resolve(42)
    }, 10 * 600_000) // more than the magic 600000
  });
}

async function run () {
  console.log('started at', new Date().toISOString())
  console.log('should throw a timeout exception after 600000 ms (10 minutes)')

  const result = await pool.exec(testTimeout, [])
  console.log('result', result)

  await pool.terminate()
}

run().catch(console.error)

Can you provide a minimal example (with workerpool only involved) that demonstrates the issue?

MarianoFacundoArch commented 1 year ago

Found the issue, thank you.

There was a library that is made with workerpool, and i use that library in another part of the code after the workerpool