Node.js › Background Jobs & Queues
What is a 'stalled' job in BullMQ, and what causes it?
IntermediateAnswer
A stalled job is one that was picked up by a worker but the worker failed to report progress or completion within the expected lock-renewal window -- typically caused by the worker process crashing mid-job, being killed abruptly, or the event loop being blocked long enough that BullMQ's internal lock-renewal mechanism couldn't run in time. BullMQ detects stalled jobs and, depending on configuration, automatically moves them back to the queue to be retried by another (or the same) worker.
const worker = new Worker('jobs', processJob, {
connection,
lockDuration: 30000, // how long a job lock is held before needing renewal
maxStalledCount: 2, // how many times a job can stall before failing permanently
});
worker.on('stalled', (jobId) => {
console.warn(`Job ${jobId} stalled and will be retried`);
});Real-world example A worker running a CPU-intensive synchronous image transformation without yielding to the event loop periodically triggers false stalled-job detections, since the blocked event loop prevents BullMQ's lock-renewal heartbeat from running in time; the fix involves offloading that CPU work to a worker thread so the main event loop stays responsive.