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 TwoInputNonBroadcastWindowProcessOperator.onRecord1, after MergingWindowSet.addWindow(...) returns the post-merge representative window (actualWindow) and the late check passes, getStateWindow(actualWindow) must return the state window holding the contents. A null result violates the in-flight window set invariant: addWindow guaranteed a mapping that the set no longer contains. The message prints the originally assigned 'window' rather than 'actualWindow', so the named window can be misleading.

Source

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

                                        // state window
                                        leftWindowMergingState.mergeNamespaces(
                                                stateWindowResult, mergedStateWindows);
                                        rightWindowMergingState.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.");
                }

                leftWindowState.setCurrentNamespace(stateWindow);
                collector.setTimestamp(window.maxTimestamp());
                windowFunctionContext.setWindow(window);
                windowProcessFunction.onRecord1(
                        element.getValue(), collector, partitionedContext, windowFunctionContext);

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

                TriggerResult triggerResult =
                        triggerContext.onElement(
                                new StreamRecord<>(
                                        TaggedUnion.one(element.getValue()),
                                        element.getTimestamp()));

View on GitHub (pinned to 2f3c205e92)

Solutions

  1. Look for an earlier exception in the same task's logs (user function, trigger, MergeFunction) and fix that root cause first.
  2. Audit custom window types: equals()/hashCode() must agree with the window serializer used by the 'merging-window-set' state.
  3. Never restore state produced under a different assigner configuration; start a new checkpoint chain when the window semantics change.
  4. If no user code is involved, file a Flink JIRA with job graph, assigner, backend and checkpoint history instead of retrying the job.
Defensive patterns

Strategy: try-catch

Try / catch

try {
    env.execute("two-input-session-job");
} catch (Exception e) {
    if (e instanceof IllegalStateException
            && String.valueOf(e.getMessage()).contains("not in in-flight window set")) {
        // invariant break after addWindow: alert with checkpoint id, halt restart loop
        alertAndHalt(lastCheckpointId, e);
    }
    throw e;
}

Prevention

When it happens

Trigger: getStateWindow(actualWindow) == null after addWindow returned actualWindow for a left-input record: a prior merge/callback threw after mutating state, the restored 'merging-window-set' state does not match the current window serializer or assigner (equals/hashCode mismatch), or an internal bug in the @Experimental two-input window extension.

Common situations: Custom window types with equals()/hashCode() inconsistent with the serializer; savepoints restored across changed session gaps/window classes; user exceptions on the merge path leaving partial updates; checkpoint compatibility across Flink versions.

Related errors


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