Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • B bull
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 175
    • Issues 175
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 9
    • Merge requests 9
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OptimalBits
  • bull
  • Issues
  • #1404
Closed
Open
Issue created Jul 31, 2019 by Administrator@rootContributor

Job#finished causes unhandled promise rejection when is queue closing [BUG]

Created by: misos1

Description

There is check whether is queue closing and then is promise rejected but as next is called scripts.isFinished. Probably that part should be in "else" or there should be "return;" after "reject".

Please remove that awful 5 seconds watchdog altogether. It is doable and would be much more better as I mentioned in https://github.com/OptimalBits/bull/issues/1371.

Job.prototype.finished in job.js:

            //
            // Watchdog
            //
            const interval = setInterval(() => {
              if (this._isQueueClosing()) {
                removeListeners();
                // TODO(manast) maybe we would need a more graceful way to get out of this interval.
                reject(
                  new Error(
                    'cannot check if job is finished in a closing queue.'
                  )
                );
              }
              scripts.isFinished(this).then(status => {
                const finished = status > 0;
                if (finished) {
                  Job.fromId(this.queue, this.id).then(job => {
                    removeListeners();
                    if (status == 2) {
                      reject(new Error(job.failedReason));
                    } else {
                      resolve(job.returnvalue);
                    }
                  });
                }
              });
            }, FINISHED_WATCHDOG);

Minimal, Working Test code to reproduce the issue.

let Queue = require("bull");
let queue = new Queue("queue");
queue.process(_job => console.log("started"));
(async function()
{
	let job = await queue.add({});
	await job.finished();
	await job.remove();
	console.log("removed");
	queue.close();
	try
	{
		await job.finished();
	}
	catch(err)
	{
		console.log(err);
	}
})();

Possible output:

started
removed
// after 5 seconds
Error: cannot check if job is finished in a closing queue.
    at Timeout.<anonymous> (node_modules/bull/lib/job.js:469:19)
    at listOnTimeout (internal/timers.js:531:17)
    at processTimers (internal/timers.js:475:7)
(node:35153) UnhandledPromiseRejectionWarning: Error: Connection is closed.
    at Redis.sendCommand (node_modules/ioredis/built/redis.js:552:24)
    at Script.execute (node_modules/ioredis/built/script.js:23:34)
    at Redis.isFinished (node_modules/ioredis/built/commander.js:152:24)
    at Object.isFinished (node_modules/bull/lib/scripts.js:235:29)
    at Timeout.<anonymous> (node_modules/bull/lib/job.js:474:23)
    at listOnTimeout (internal/timers.js:531:17)
    at processTimers (internal/timers.js:475:7)

Bull version

3.10.0

Additional information

Assignee
Assign to
Time tracking