{"record":{"id":"069a64a5defe7c09","repo":"denoland/deno","slug":"bad-cluster-schedulingpolicy-schedulingpolicy","errorCode":null,"errorMessage":"Bad cluster.schedulingPolicy: ${schedulingPolicy}","messagePattern":"Bad cluster\\.schedulingPolicy: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"ext/node/polyfills/internal/cluster/primary.ts","lineNumber":117,"sourceCode":"    const settings = {\n      args: ArrayPrototypeSlice(process.argv, 2),\n      exec: process.argv[1],\n      execArgv: process.execArgv,\n      silent: false,\n      ...cluster.settings,\n      ...options,\n    };\n\n    cluster.settings = settings;\n\n    if (setupCalled === true) {\n      return process.nextTick(setupSettingsNT, settings);\n    }\n\n    setupCalled = true;\n    schedulingPolicy = cluster.schedulingPolicy;\n    if (schedulingPolicy !== SCHED_NONE && schedulingPolicy !== SCHED_RR) {\n      throw new Error(`Bad cluster.schedulingPolicy: ${schedulingPolicy}`);\n    }\n\n    process.nextTick(setupSettingsNT, settings);\n  };\n  cluster.setupMaster = cluster.setupPrimary;\n\n  function setupSettingsNT(settings: any) {\n    cluster.emit(\"setup\", settings);\n  }\n\n  function createWorkerProcess(id: number, env: any) {\n    const workerEnv: any = {\n      ...(process as any).env,\n      ...env,\n      NODE_UNIQUE_ID: `${id}`,\n    };\n    if (schedulingPolicy === SCHED_RR) {\n      workerEnv.NODE_CLUSTER_SCHED_POLICY = \"rr\";","sourceCodeStart":99,"sourceCodeEnd":135,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/ext/node/polyfills/internal/cluster/primary.ts#L99-L135","documentation":"cluster.setupPrimary() (alias setupMaster) copies cluster.schedulingPolicy into a local and requires it to be exactly SCHED_NONE or SCHED_RR, the numeric constants exported by the cluster module; anything else throws a plain Error with this message. The default derives from NODE_CLUSTER_SCHED, so an unexpected value usually means code or config assigned a string like \"rr\" or left the policy undefined.","triggerScenarios":"cluster.schedulingPolicy = \"rr\" followed by setupPrimary(); setupPrimary({ schedulingPolicy: Number(process.env.SCHED) }) where the env var is unset (NaN) or not 1/2.","commonSituations":"Docs or blog snippets that use string policy names; env-driven config with a typo or missing value; hard-coded numeric constants ported between versions.","solutions":["Use the exported constants: cluster.SCHED_RR / cluster.SCHED_NONE","Validate before setup: if (p !== cluster.SCHED_RR && p !== cluster.SCHED_NONE) throw","Map config strings to constants in one place: \"rr\" -> cluster.SCHED_RR, \"none\" -> cluster.SCHED_NONE"],"exampleFix":"// before\ncluster.schedulingPolicy = process.env.CLUSTER_SCHED; // \"rr\" -> throws\ncluster.setupPrimary();\n\n// after\nconst policy = process.env.CLUSTER_SCHED === \"none\"\n  ? cluster.SCHED_NONE\n  : cluster.SCHED_RR;\ncluster.schedulingPolicy = policy;\ncluster.setupPrimary();","handlingStrategy":"validation","validationCode":"const policy = cluster.schedulingPolicy;\nif (policy !== cluster.SCHED_RR && policy !== cluster.SCHED_NONE) {\n  throw new Error(`invalid schedulingPolicy: ${policy}`);\n}\ncluster.setupPrimary();","typeGuard":"const isValidSchedulingPolicy = (p) => p === cluster.SCHED_RR || p === cluster.SCHED_NONE;","tryCatchPattern":null,"preventionTips":["Only assign schedulingPolicy from the module's exported constants","Map config strings to constants in one parser, never assign raw config","Validate policy right before setupPrimary so failures point at the config source"],"tags":["cluster","configuration","node-compat"],"backgroundTag":"invalid-config-value","analyzedSha":"9ad36f7a2cce60488e6ec52283efb32efddaf93a","analyzedAt":"2026-08-20T13:07:44.778Z","contentChangedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}