{"record":{"id":"deb6f071cb7e362e","repo":"apache/flink","slug":"the-end-timestamp-of-an-event-time-window-cannot-b-deb6f0","errorCode":null,"errorMessage":"The end timestamp of an event-time window cannot become earlier than the current watermark by merging. Current event time: {eventTime} window: {mergeResult}","messagePattern":"The end timestamp of an event-time window cannot become earlier than the current watermark by merging\\. Current event time: (.+?) window: (.+?)","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"flink-datastream/src/main/java/org/apache/flink/datastream/impl/extension/window/operators/TwoOutputWindowProcessOperator.java","lineNumber":261,"sourceCode":"                // is the merged window and we work with that. If we don't merge then\n                // actualWindow == window\n                W actualWindow =\n                        mergingWindows.addWindow(\n                                window,\n                                new MergingWindowSet.MergeFunction<>() {\n                                    @Override\n                                    public void merge(\n                                            W mergeResult,\n                                            Collection<W> mergedWindows,\n                                            W stateWindowResult,\n                                            Collection<W> mergedStateWindows)\n                                            throws Exception {\n\n                                        if ((windowAssigner.isEventTime()\n                                                && mergeResult.maxTimestamp() + allowedLateness\n                                                        <= internalTimerService\n                                                                .currentWatermark())) {\n                                            throw new UnsupportedOperationException(\n                                                    \"The end timestamp of an \"\n                                                            + \"event-time window cannot become earlier than the current watermark \"\n                                                            + \"by merging. Current event time: \"\n                                                            + internalTimerService\n                                                                    .currentWatermark()\n                                                            + \" window: \"\n                                                            + mergeResult);\n                                        } else if (!windowAssigner.isEventTime()) {\n                                            long currentProcessingTime =\n                                                    internalTimerService.currentProcessingTime();\n                                            if (mergeResult.maxTimestamp()\n                                                    <= currentProcessingTime) {\n                                                throw new UnsupportedOperationException(\n                                                        \"The end timestamp of a \"\n                                                                + \"processing-time window cannot become earlier than the current processing time \"\n                                                                + \"by merging. Current processing time: \"\n                                                                + currentProcessingTime\n                                                                + \" window: \"","sourceCodeStart":243,"sourceCodeEnd":279,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-datastream/src/main/java/org/apache/flink/datastream/impl/extension/window/operators/TwoOutputWindowProcessOperator.java#L243-L279","documentation":"Thrown from the MergeFunction callback in TwoOutputWindowProcessOperator while a record is added to an event-time session window. The merge result must still be valid at the current watermark: mergeResult.maxTimestamp() + allowedLateness must exceed the watermark, otherwise the merged session would already be expired and the merge is refused with UnsupportedOperationException. The message carries the watermark and the offending mergeResult window.","triggerScenarios":"An out-of-order record for an event-time session window (WindowStrategy.session(gap, TimeType.EVENT)) merges sessions into a window whose end plus lateness is at/before the watermark; since session strategies default to no lateness, any merge result that expires at the current watermark throws.","commonSituations":"Watermark out-of-orderness smaller than real delay on the feeding stream; late side-output logic missing; replays/backfills after watermarks advanced; small session gaps amplifying sensitivity to skew.","solutions":["Bound out-of-orderness generously: watermark delay >= max event delay + session gap.","Intercept late records upstream (compare timestamp to currentWatermark()) and route them to a side output before the two-output window operator.","Use tumbling/sliding with explicit allowedLateness when merging is unnecessary.","Track watermark lag metrics to size the delay budget from measured data."],"exampleFix":"// before\nWatermarkStrategy.<Event>forMonotonousTimestamps();\nstream.process(twoOutputFn, WindowStrategy.session(Duration.ofMinutes(10)));\n// after\nWatermarkStrategy.<Event>forBoundedOutOfOrderness(Duration.ofMinutes(15));\nstream.process(twoOutputFn, WindowStrategy.session(Duration.ofMinutes(10)));","handlingStrategy":"validation","validationCode":"// keep would-be-expired merges away from the two-output window operator\nlong wm = ctx.currentWatermark();\nif (event.timestamp() + sessionGapMs + maxDelayMs <= wm) {\n    ctx.output(LATE_TAG, event);\n    return;\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Watermark delay >= max event delay + session gap","Side-output late records before two-output windowed operators","Use tumbling/sliding with allowedLateness when session merging is not essential"],"tags":["flink","datastream-v2","windowing","session-windows","two-output","event-time","late-data"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}