{"record":{"id":"3af3e61cc854dae9","repo":"apache/dolphinscheduler","slug":"the-post-serialcommand-except-waiting-state-but","errorCode":null,"errorMessage":"\"The post SerialCommand except WAITING state but -> \" + serialCommand.getState()","messagePattern":"\"The post SerialCommand except WAITING state but -> \" \\+ serialCommand\\.getState\\(\\)","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/engine/workflow/serial/SerialCommandDiscardHandler.java","lineNumber":51,"sourceCode":"public class SerialCommandDiscardHandler extends AbstractSerialCommandHandler {\n\n    @Override\n    public void handle(SerialCommandsGroup serialCommandsGroup) {\n        // If the first item in the queue is not running, then notify it to run.\n        // Discard all other items in the queue.\n        List<SerialCommandDto> serialCommands = serialCommandsGroup.getSerialCommands();\n        for (int i = 0; i < serialCommands.size(); i++) {\n            SerialCommandDto serialCommand = serialCommands.get(i);\n            if (i == 0) {\n                if (serialCommand.getState() == SerialCommandDto.State.WAITING) {\n                    launchSerialCommand(serialCommand);\n                    log.info(\"Launched SerialCommand: {}\", serialCommand);\n                }\n                continue;\n            }\n            // Discard all other items in the queue.\n            if (serialCommand.getState() != SerialCommandDto.State.WAITING) {\n                throw new IllegalStateException(\n                        \"The post SerialCommand except WAITING state but -> \" + serialCommand.getState());\n            }\n            discardSerialCommandAndStopWorkflowInstanceInDB(serialCommand);\n            log.info(\"Discard SerialCommand: {}\", serialCommand);\n        }\n    }\n\n}\n","sourceCodeStart":33,"sourceCodeEnd":60,"githubUrl":"https://github.com/apache/dolphinscheduler/blob/02eac45a1b6676e639fcbfb4be2243de5771b05d/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/engine/workflow/serial/SerialCommandDiscardHandler.java#L33-L60","documentation":"Thrown by SerialCommandDiscardHandler.handle when a serial command in the queue is neither LAUNCHED-eligible nor in WAITING state. The handler expects all non-first queued commands to be WAITING so they can be discarded; any other state violates the handler's invariant.","triggerScenarios":"During SERIAL_DISCARD handling, iterating grouped serial commands and encountering a command whose state is not WAITING (e.g. already started or finished concurrently).","commonSituations":"Race between serial command processing and queue inspection; corrupted serial queue state after master crash/failover.","solutions":["Inspect the serial command's state in DB to see why it is not WAITING","Add logging of all serial command states before discard to diagnose races","Restart master to rebuild serial queue state","Upgrade to a version where discard handling tolerates non-WAITING terminal states"],"exampleFix":"// before\nif (serialCommand.getState() != SerialCommandDto.State.WAITING) {\n    throw new IllegalStateException(...);\n}\n// after\nif (serialCommand.getState() != SerialCommandDto.State.WAITING) {\n    log.warn(\"Skipping non-WAITING serial command: {}\", serialCommand);\n    continue;\n}","handlingStrategy":"validation","validationCode":"List<SerialCommandDto> queue = serialCommandDao.queryByWorkflowCode(code);\nboolean allWaitingOrFirst = queue.stream().skip(1).allMatch(c -> c.getState() == SerialCommandDto.State.WAITING);","typeGuard":"boolean discardable(SerialCommandDto c) { return c.getState() == SerialCommandDto.State.WAITING; }","tryCatchPattern":"try { discardHandler.handle(group); } catch (IllegalStateException e) { log.error(\"serial queue inconsistent: {}\", e.getMessage()); resyncSerialQueue(group); }","preventionTips":["Don't mutate serial command states outside the coordinator","Resync serial queue state after master crash","Add state assertions/logging before discard operations"],"tags":["java","master","serial-workflow"],"backgroundTag":"invalid-state-transition","analyzedSha":"02eac45a1b6676e639fcbfb4be2243de5771b05d","analyzedAt":"2026-09-06T17:43:00.555Z","contentChangedAt":"2026-09-06T17:43:00.555Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}