{"record":{"id":"2c4758069957949f","repo":"nathanmarz/storm","slug":"task-id-should-not-exceed-short-max-value","errorCode":null,"errorMessage":"Task ID should not exceed ${Short.MAX_VALUE}","messagePattern":"Task ID should not exceed (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"storm-netty/src/jvm/backtype/storm/messaging/netty/MessageBatch.java","lineNumber":163,"sourceCode":"        return bout.buffer();\n    }\n\n    /**\n     * write a TaskMessage into a stream\n     *\n     * Each TaskMessage is encoded as:\n     *  task ... short(2)\n     *  len ... int(4)\n     *  payload ... byte[]     *  \n     */\n    private void writeTaskMessage(ChannelBufferOutputStream bout, TaskMessage message) throws Exception {\n        int payload_len = 0;\n        if (message.message() != null)\n            payload_len =  message.message().length;\n\n        int task_id = message.task();\n        if (task_id > Short.MAX_VALUE)\n            throw new RuntimeException(\"Task ID should not exceed \"+Short.MAX_VALUE);\n        \n        bout.writeShort((short)task_id);\n        bout.writeInt(payload_len);\n        if (payload_len >0)\n            bout.write(message.message());\n    }\n}","sourceCodeStart":145,"sourceCodeEnd":170,"githubUrl":"https://github.com/nathanmarz/storm/blob/cdb116e942666973bc4eaa0df098d5bab82739e7/storm-netty/src/jvm/backtype/storm/messaging/netty/MessageBatch.java#L145-L170","documentation":"The wire format writes the task id as a 2-byte short. writeTaskMessage (called from MessageBatch.buffer) validates this and throws when a task id exceeds Short.MAX_VALUE (32767), since it cannot be encoded as writeShort(task_id).","triggerScenarios":"A topology whose task IDs exceed 32767 — e.g. very large topologies with many executors — when batching TaskMessages for sending over netty and calling buffer().","commonSituations":"Massively parallel topologies where storm-assigned task ids exceed the short range; custom code fabricating task ids without checking the short bound; ports of the transport to newer Storm versions with larger task counts.","solutions":["Reduce topology parallelism (fewer executors/tasks) so task ids stay below 32768.","Upgrade Storm to a version whose transport uses int task ids instead of shorts.","Validate task ids in custom message-producing code against Short.MAX_VALUE before sending.","Patch the transport to widen the task id field to 4 bytes (both sender and receiver must agree)."],"exampleFix":"// before\nint taskId = 40000;\nbatch.add(new TaskMessage(taskId, payload));\n// after\nassert taskId <= Short.MAX_VALUE;\nbatch.add(new TaskMessage(taskId, payload)); // or restructure topology to keep ids < 32768","handlingStrategy":"validation","validationCode":"if (taskId > Short.MAX_VALUE || taskId < 0) {\n    throw new IllegalArgumentException(\"Task ID must fit in a short: \" + taskId);\n}","typeGuard":null,"tryCatchPattern":"try {\n    byte[] buf = batch.buffer();\n} catch (RuntimeException e) {\n    if (e.getMessage().contains(\"Task ID should not exceed\")) {\n        // restructure topology parallelism or upgrade transport\n    } else { throw e; }\n}","preventionTips":["Keep topology task counts below 32768 (cap executors/workers accordingly).","Validate fabricated task ids in custom code against Short.MAX_VALUE.","Prefer a Storm version whose netty transport encodes task ids as int."],"tags":["netty","serialization","task-id","messaging"],"backgroundTag":"value-out-of-range","analyzedSha":"cdb116e942666973bc4eaa0df098d5bab82739e7","analyzedAt":"2026-09-12T14:30:00.714Z","contentChangedAt":"2026-09-12T14:30:00.714Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}