{"record":{"id":"e8f721b13adfeb35","repo":"apache/flink","slug":"window-window-is-not-in-in-flight-window-set","errorCode":null,"errorMessage":"Window {window} is not in in-flight window set.","messagePattern":"Window (.+?) is not in in-flight window set\\.","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"flink-datastream/src/main/java/org/apache/flink/datastream/impl/extension/window/operators/MergingWindowSet.java","lineNumber":120,"sourceCode":"     * {@code Window} in which we keep the actual state of a given in-flight window. Windows might\n     * expand but we keep to original state window for keeping the elements of the window to avoid\n     * costly state juggling.\n     *\n     * @param window The window for which to get the state window.\n     */\n    public W getStateWindow(W window) {\n        return mapping.get(window);\n    }\n\n    /**\n     * Removes the given window from the set of in-flight windows.\n     *\n     * @param window The {@code Window} to remove.\n     */\n    public void retireWindow(W window) {\n        W removed = this.mapping.remove(window);\n        if (removed == null) {\n            throw new IllegalStateException(\n                    \"Window \" + window + \" is not in in-flight window set.\");\n        }\n    }\n\n    /**\n     * Adds a new {@code Window} to the set of in-flight windows. It might happen that this triggers\n     * merging of previously in-flight windows. In that case, the provided {@link MergeFunction} is\n     * called.\n     *\n     * <p>This returns the window that is the representative of the added window after adding. This\n     * can either be the new window itself, if no merge occurred, or the newly merged window. Adding\n     * an element to a window or calling trigger functions should only happen on the returned\n     * representative. This way, we never have to deal with a new window that is immediately\n     * swallowed up by another window.\n     *\n     * <p>If the new window is merged, the {@code MergeFunction} callback arguments also don't\n     * contain the new window as part of the list of merged windows.\n     *","sourceCodeStart":102,"sourceCodeEnd":138,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-datastream/src/main/java/org/apache/flink/datastream/impl/extension/window/operators/MergingWindowSet.java#L102-L138","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// before retiring a window, confirm it is still in flight\nif (mergingWindows.getStateWindow(window) != null) {\n    mergingWindows.retireWindow(window);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["flink","datastream-v2","windowing","session-windows","merging-window-set","state-consistency"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}