{"record":{"id":"340a8997a228e059","repo":"caolan/async","slug":"concurrency-must-not-be-zero","errorCode":null,"errorMessage":"Concurrency must not be zero","messagePattern":"Concurrency must not be zero","errorType":"validation","errorClass":"RangeError","httpStatus":null,"severity":"error","filePath":"lib/internal/queue.js","lineNumber":11,"sourceCode":"import onlyOnce from './onlyOnce.js'\nimport setImmediate from './setImmediate.js'\nimport DLL from './DoublyLinkedList.js'\nimport wrapAsync from './wrapAsync.js'\n\nexport default function queue(worker, concurrency, payload) {\n    if (concurrency == null) {\n        concurrency = 1;\n    }\n    else if(concurrency === 0) {\n        throw new RangeError('Concurrency must not be zero');\n    }\n\n    var _worker = wrapAsync(worker);\n    var numRunning = 0;\n    var workersList = [];\n    const events = {\n        error: [],\n        drain: [],\n        saturated: [],\n        unsaturated: [],\n        empty: []\n    }\n\n    function on (event, handler) {\n        events[event].push(handler)\n    }\n\n    function once (event, handler) {","sourceCodeStart":1,"sourceCodeEnd":29,"githubUrl":"https://github.com/caolan/async/blob/13dfaf13f3fc809ba1c9c39d5e267ac6959cbf4a/lib/internal/queue.js#L1-L29","documentation":"async.queue and async.cargo validate the concurrency argument at construction. null/undefined defaults to 1, but an explicit 0 would create a worker pool that never processes any task, so a RangeError is thrown. Concurrency must be a positive number.","triggerScenarios":"new async.queue(worker, 0), async.cargo(worker, 0), or passing a variable that is exactly 0 (parsed config value, Math.floor of something < 1). Note: null/undefined is silently treated as 1, only literal 0 throws.","commonSituations":"Reading concurrency from env/config where 0 was used to mean 'unlimited', numeric parsing returning 0 for empty strings (Number('') === 0), CPU-count computations yielding 0.","solutions":["Pass a positive concurrency: Math.max(1, parsed)","If 'unlimited' is desired, omit the argument (defaults to 1) or implement your own drain-based batching — 0 is not a valid sentinel","Normalize config: const c = parseInt(raw, 10); if (!c) c = 1","Fix the parsing/computation that produced 0"],"exampleFix":"// before\nconst q = async.queue(worker, Number(process.env.CONCURRENCY)); // 0 when unset\n// after\nconst raw = parseInt(process.env.CONCURRENCY, 10);\nconst q = async.queue(worker, raw > 0 ? raw : 1);","handlingStrategy":"validation","validationCode":"const assertQueueConcurrency = (n) => { const v = n == null ? 1 : Number(n); if (v === 0 || Number.isNaN(v)) throw new RangeError('Concurrency must not be zero'); return v; };","typeGuard":"function isValidConcurrency(n) {\n  return n == null || (Number.isFinite(n) && n >= 1);\n}","tryCatchPattern":"try {\n  const q = async.queue(worker, concurrency);\n} catch (err) {\n  if (err instanceof RangeError) {\n    console.error('Fix concurrency config; defaulting to 1');\n  } else throw err;\n}","preventionTips":["Remember 0 is invalid; null/undefined means 1","Guard env-derived values: raw > 0 ? raw : 1","Note Number('') is 0 — parse carefully"],"tags":["async","queue","concurrency"],"backgroundTag":"invalid-concurrency-limit","analyzedSha":"13dfaf13f3fc809ba1c9c39d5e267ac6959cbf4a","analyzedAt":"2026-08-28T22:50:46.507Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}