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

In TwoOutputWindowProcessOperator, after addWindow returns the post-merge representative window (actualWindow), getStateWindow(actualWindow) must yield the state window holding its contents; null means the in-flight window set is inconsistent with addWindow's contract and IllegalStateException is thrown. As elsewhere, the message reports the originally assigned 'window', not the actualWindow used in the failed lookup.

Source

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

                                        // 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);
                mainCollector.setTimestamp(window.maxTimestamp());
                sideCollector.setTimestamp(window.maxTimestamp());
                windowFunctionContext.setWindow(window);
                windowProcessFunction.onRecord(
                        element.getValue(),
                        mainCollector,
                        sideCollector,
                        partitionedContext,
                        windowFunctionContext);

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

                TriggerResult triggerResult = triggerContext.onElement(element);

View on GitHub (pinned to 2f3c205e92)

Solutions

  1. Fix any earlier exception in the same task logs first.
  2. Audit custom window equals()/hashCode() against the window serializer.
  3. Use a fresh checkpoint chain after changing assigner/window semantics.
  4. Report invariant breaks without user-code involvement as Flink bugs with full context.
Defensive patterns

Strategy: try-catch

Try / catch

try {
    env.execute("two-output-session-job");
} catch (Exception e) {
    if (e instanceof IllegalStateException
            && String.valueOf(e.getMessage()).contains("not in in-flight window set")) {
        haltWithDiagnostics(jobId, lastCheckpoint, e); // do not blind-restart
    }
    throw e;
}

Prevention

When it happens

Trigger: A record's session merge completes but the 'merging-window-set' has no mapping for the returned window: half-applied state from an earlier exception, restore-state mismatch with the window serializer/assigner, or an extension bug.

Common situations: Custom windows with equals/hashCode inconsistent with serialization; savepoint restore across assigner changes; exceptions from two-output window functions during merges; version skew.

Related errors


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