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
MergingWindowSet tracks the in-flight (active) windows of a merging assigner (session windows) and maps each window to the state window that holds its contents. retireWindow() removes a window from this set and throws IllegalStateException when mapping.remove(window) returns null, i.e. the window was never added or was already retired. When this fires inside a window operator it means the 'merging-window-set' state is inconsistent with the operator's view of active windows, which points to corrupted/half-updated state or a lifecycle bug, not to bad user data.
Source
Thrown at flink-datastream/src/main/java/org/apache/flink/datastream/impl/extension/window/operators/MergingWindowSet.java:120
* {@code Window} in which we keep the actual state of a given in-flight window. Windows might
* expand but we keep to original state window for keeping the elements of the window to avoid
* costly state juggling.
*
* @param window The window for which to get the state window.
*/
public W getStateWindow(W window) {
return mapping.get(window);
}
/**
* Removes the given window from the set of in-flight windows.
*
* @param window The {@code Window} to remove.
*/
public void retireWindow(W window) {
W removed = this.mapping.remove(window);
if (removed == null) {
throw new IllegalStateException(
"Window " + window + " is not in in-flight window set.");
}
}
/**
* Adds a new {@code Window} to the set of in-flight windows. It might happen that this triggers
* merging of previously in-flight windows. In that case, the provided {@link MergeFunction} is
* called.
*
* <p>This returns the window that is the representative of the added window after adding. This
* can either be the new window itself, if no merge occurred, or the newly merged window. Adding
* an element to a window or calling trigger functions should only happen on the returned
* representative. This way, we never have to deal with a new window that is immediately
* swallowed up by another window.
*
* <p>If the new window is merged, the {@code MergeFunction} callback arguments also don't
* contain the new window as part of the list of merged windows.
*View on GitHub (pinned to 2f3c205e92)
Solutions
- Inspect the task logs for an earlier exception (from a WindowProcessFunction, trigger, or MergeFunction) in the same task before this one - a half-applied update is the usual root cause.
- If a custom MergingWindowAssigner is in use, audit its mergeWindows() contract: merged-away windows and the result window must be reported consistently for identical inputs.
- Test checkpoint-restore behavior with the same job under load; if the error only appears after restore, verify savepoint compatibility of the 'merging-window-set' state across the Flink versions involved.
- If the stack trace contains no user code and no prior exception, collect job graph, assigner, state backend and checkpoint history and file a Flink JIRA - this is an internal invariant violation in an @Experimental extension.
Defensive patterns
Strategy: validation
Validate before calling
// before retiring a window, confirm it is still in flight
if (mergingWindows.getStateWindow(window) != null) {
mergingWindows.retireWindow(window);
} Prevention
- Keep user code inside window functions and MergeFunctions exception-free; a throw mid-merge leaves the window set half-updated
- Make cleanup idempotent - never retire a window twice
- Test checkpoint restore under load for every session-window job before production
When it happens
Trigger: A session-window operator calls mergingWindows.retireWindow(actualWindow) after WindowUtils.isWindowLate(...) flags the window as late; the throw happens when the same window was already retired (double retirement) or was never inserted by MergingWindowSet.addWindow(). Reached with EventTimeSessionWindows / ProcessingTimeSessionWindows when cleanup timers and record processing disagree, or when an earlier exception (from a MergeFunction or user WindowProcessFunction) left the window set partially updated.
Common situations: Restore from a checkpoint/savepoint taken while a merge was in progress; exceptions thrown from user window functions that leave the window set half-updated; custom MergingWindowAssigner implementations whose mergeWindows() results are inconsistent; Flink version changes that altered the 'merging-window-set' state layout.
Related errors
- Window {window} is not in in-flight window set.
- Window {window} is not in in-flight window set.
- Window {window} is not in in-flight window set.
- The window uses a merging assigner, but the window state is
- The end timestamp of an event-time window cannot become earl
AI-assisted analysis of apache/flink@2f3c205e92 (2026-08-14).
Data as JSON: /api/errors/e8f721b13adfeb35.
Report an issue: GitHub.