{"record":{"id":"f70aafd903622e68","repo":"apache/pulsar","slug":"function-parallelism-must-be-a-positive-number","errorCode":null,"errorMessage":"Function parallelism must be a positive number","messagePattern":"Function parallelism must be a positive number","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"pulsar-functions/utils/src/main/java/org/apache/pulsar/functions/utils/FunctionConfigUtils.java","lineNumber":838,"sourceCode":"            }\n        }\n\n        if (!isEmpty(functionConfig.getLogTopic())) {\n            if (!TopicName.isValid(functionConfig.getLogTopic())) {\n                throw new IllegalArgumentException(\n                        String.format(\"LogTopic topic %s is invalid\", functionConfig.getLogTopic()));\n            }\n        }\n\n        if (!isEmpty(functionConfig.getDeadLetterTopic())) {\n            if (!TopicName.isValid(functionConfig.getDeadLetterTopic())) {\n                throw new IllegalArgumentException(\n                        String.format(\"DeadLetter topic %s is invalid\", functionConfig.getDeadLetterTopic()));\n            }\n        }\n\n        if (functionConfig.getParallelism() != null && functionConfig.getParallelism() <= 0) {\n            throw new IllegalArgumentException(\"Function parallelism must be a positive number\");\n        }\n        // Ensure that topics aren't being used as both input and output\n        verifyNoTopicClash(allInputTopics, functionConfig.getOutput());\n\n        WindowConfig windowConfig = functionConfig.getWindowConfig();\n        if (windowConfig != null) {\n            // set auto ack to false since windowing framework is responsible\n            // for acking and not the function framework\n            @SuppressWarnings(\"deprecation\")\n            Boolean windowAutoAck = functionConfig.getAutoAck();\n            if (windowAutoAck != null && windowAutoAck) {\n                throw new IllegalArgumentException(\"Cannot enable auto ack when using windowing functionality\");\n            }\n            WindowConfigUtils.validate(windowConfig);\n        }\n\n        if (functionConfig.getResources() != null) {\n            ResourceConfigUtils.validate(functionConfig.getResources());","sourceCodeStart":820,"sourceCodeEnd":856,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-functions/utils/src/main/java/org/apache/pulsar/functions/utils/FunctionConfigUtils.java#L820-L856","documentation":"FunctionConfig parallelism controls how many instances of the function run. doCommonChecks rejects configs where parallelism is explicitly set to zero or a negative number, since the runtime cannot launch a non-positive number of instances.","triggerScenarios":"createFunction/updateFunction with functionConfig.getParallelism() != null && parallelism <= 0: e.g. parallelism: 0 in YAML, a computed value defaulting to 0, or CLI --parallelism 0.","commonSituations":"Programmatic config generation where parallelism comes from an unset integer variable (int default 0), autoscaling scripts computing 0 replicas, copy-pasted manifests with parallelism commented incorrectly.","solutions":["Set parallelism to a positive integer (typically 1 for single-instance, N for scaled-out)","Only set the field when you have a computed positive value; leave it null to use the default","Guard programmatic generation: Math.max(1, computedParallelism)","Fix autoscaling logic that can emit 0"],"exampleFix":"// before\nconfig.setParallelism(replicas); // replicas could be 0\n// after\nconfig.setParallelism(Math.max(1, replicas));","handlingStrategy":"validation","validationCode":"Integer p = config.getParallelism();\nif (p != null && p <= 0) {\n    throw new IllegalArgumentException(\"parallelism must be positive, got \" + p);\n}","typeGuard":"boolean positiveParallelism(FunctionConfig c) {\n    return c.getParallelism() == null || c.getParallelism() > 0;\n}","tryCatchPattern":"try {\n    admin.functions().createFunction(functionConfig, sourceConfigLocation);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().contains(\"parallelism must be a positive number\")) {\n        config.setParallelism(1); // or a computed positive value, then retry once\n    } else { throw e; }\n}","preventionTips":["Use Math.max(1, computed) when generating parallelism programmatically","Leave parallelism null to inherit defaults instead of setting 0","Validate integer fields that come from autoscaling computations","Add manifest linting that rejects parallelism <= 0"],"tags":["pulsar-functions","validation","parallelism","configuration"],"backgroundTag":"invalid-function-config","analyzedSha":"820761864ed8e2a7d2e52dd9763ad2ae117c1395","analyzedAt":"2026-09-06T00:14:20.138Z","contentChangedAt":"2026-09-06T00:14:20.138Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}