apache/dolphinscheduler · error · IllegalStateException

"The post SerialCommand except WAITING state but -> " + seri

Error message

"The post SerialCommand except WAITING state but -> " + serialCommand.getState()

What it means

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.

Source

Thrown at dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/engine/workflow/serial/SerialCommandDiscardHandler.java:51

public class SerialCommandDiscardHandler extends AbstractSerialCommandHandler {

    @Override
    public void handle(SerialCommandsGroup serialCommandsGroup) {
        // If the first item in the queue is not running, then notify it to run.
        // Discard all other items in the queue.
        List<SerialCommandDto> serialCommands = serialCommandsGroup.getSerialCommands();
        for (int i = 0; i < serialCommands.size(); i++) {
            SerialCommandDto serialCommand = serialCommands.get(i);
            if (i == 0) {
                if (serialCommand.getState() == SerialCommandDto.State.WAITING) {
                    launchSerialCommand(serialCommand);
                    log.info("Launched SerialCommand: {}", serialCommand);
                }
                continue;
            }
            // Discard all other items in the queue.
            if (serialCommand.getState() != SerialCommandDto.State.WAITING) {
                throw new IllegalStateException(
                        "The post SerialCommand except WAITING state but -> " + serialCommand.getState());
            }
            discardSerialCommandAndStopWorkflowInstanceInDB(serialCommand);
            log.info("Discard SerialCommand: {}", serialCommand);
        }
    }

}

View on GitHub (pinned to 02eac45a1b)

Solutions

  1. Inspect the serial command's state in DB to see why it is not WAITING
  2. Add logging of all serial command states before discard to diagnose races
  3. Restart master to rebuild serial queue state
  4. Upgrade to a version where discard handling tolerates non-WAITING terminal states

Example fix

// before
if (serialCommand.getState() != SerialCommandDto.State.WAITING) {
    throw new IllegalStateException(...);
}
// after
if (serialCommand.getState() != SerialCommandDto.State.WAITING) {
    log.warn("Skipping non-WAITING serial command: {}", serialCommand);
    continue;
}
Defensive patterns

Strategy: validation

Validate before calling

List<SerialCommandDto> queue = serialCommandDao.queryByWorkflowCode(code);
boolean allWaitingOrFirst = queue.stream().skip(1).allMatch(c -> c.getState() == SerialCommandDto.State.WAITING);

Type guard

boolean discardable(SerialCommandDto c) { return c.getState() == SerialCommandDto.State.WAITING; }

Try / catch

try { discardHandler.handle(group); } catch (IllegalStateException e) { log.error("serial queue inconsistent: {}", e.getMessage()); resyncSerialQueue(group); }

Prevention

When it happens

Trigger: During SERIAL_DISCARD handling, iterating grouped serial commands and encountering a command whose state is not WAITING (e.g. already started or finished concurrently).

Common situations: Race between serial command processing and queue inspection; corrupted serial queue state after master crash/failover.

Understand the failure class

Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.

Related errors


AI-assisted analysis of apache/dolphinscheduler@02eac45a1b (2026-09-06). Data as JSON: /api/errors/3af3e61cc854dae9. Report an issue: GitHub.