apache/flink · error · IllegalStateException

Window {window} is not in in-flight window set.

Error message

Window {window} is not in in-flight window set.

What it means

After MergingWindowSet.addWindow(...) returns the post-merge representative window (actualWindow) and the lateness check passes, OneInputWindowProcessOperator looks up the state window holding that window's contents via getStateWindow(actualWindow). A null result means the in-flight window set has no mapping for a window that addWindow just returned - an internal invariant violation indicating inconsistent 'merging-window-set' state. Note the message prints the originally assigned 'window' while the lookup used 'actualWindow', so the reported window can be misleading.

Source

Thrown at flink-datastream/src/main/java/org/apache/flink/datastream/impl/extension/window/operators/OneInputWindowProcessOperator.java:307

                                        // merge the merged state windows into the newly resulting
                                        // state window
                                        windowMergingState.mergeNamespaces(
                                                stateWindowResult, mergedStateWindows);
                                    }
                                });

                // drop if the window is already late
                if (WindowUtils.isWindowLate(
                        actualWindow, windowAssigner, internalTimerService, allowedLateness)) {
                    mergingWindows.retireWindow(actualWindow);
                    continue;
                }
                isSkippedElement = false;

                W stateWindow = mergingWindows.getStateWindow(actualWindow);
                if (stateWindow == null) {
                    throw new IllegalStateException(
                            "Window " + window + " is not in in-flight window set.");
                }

                windowState.setCurrentNamespace(stateWindow);
                outputCollector.setTimestamp(window.maxTimestamp());
                windowFunctionContext.setWindow(window);
                windowProcessFunction.onRecord(
                        element.getValue(),
                        outputCollector,
                        partitionedContext,
                        windowFunctionContext);

                triggerContext.setKey(key);
                triggerContext.setWindow(actualWindow);

                TriggerResult triggerResult = triggerContext.onElement(element);

                if (triggerResult.isFire()) {

View on GitHub (pinned to 2f3c205e92)

Solutions

  1. Check the task logs for an earlier exception (user WindowProcessFunction, trigger, MergeFunction) - the half-applied state update is the root cause; fix that first.
  2. If the window type is custom, verify its equals() and hashCode() are consistent with the window serializer used for the 'merging-window-set' state.
  3. Do not restore state taken with a different window assigner configuration (changed session gap/size or window class); start a fresh checkpoint chain instead.
  4. Otherwise capture job graph, assigner, backend and checkpoint history and file a Flink JIRA; do not blind-retry as restart loops will re-hit the same inconsistent state.
Defensive patterns

Strategy: try-catch

Try / catch

// the throw happens inside the task; surface it with context instead of blind restarts
try {
    env.execute("session-job");
} catch (IllegalStateException e) {
    if (e.getMessage() != null && e.getMessage().contains("not in in-flight window set")) {
        // invariant break: capture job id + last checkpoint, alert, and stop
        throw new IllegalStateException("window set inconsistent - see checkpoint " + lastCpId, e);
    }
    throw e;
}

Prevention

When it happens

Trigger: getStateWindow(actualWindow) returns null after addWindow promised a mapping. Reached when a previous merge callback or user function threw after mutating state (half-applied update), when the restored 'merging-window-set' state does not match the current assigner/window serializer (equals/hashCode mismatch), or via bugs in the @Experimental window extension itself.

Common situations: Custom window types whose equals()/hashCode() disagree with the window serializer so map lookups miss; restoring a savepoint taken with a different session gap or window class; exceptions from user code near the merge path leaving partial updates; Flink version skew between checkpoint producer and consumer.

Related errors


AI-assisted analysis of apache/flink@2f3c205e92 (2026-08-14). Data as JSON: /api/errors/4d14e901f79a726b. Report an issue: GitHub.