beam icon indicating copy to clipboard operation
beam copied to clipboard

[Bug]: Flink runner loses the key of buffered timers with @RequiresStableInput (@Key is null in @OnTimer)

Open alisha-1000 opened this issue 1 week ago • 2 comments

What happened?

Summary

  • With @RequiresStableInput on a stateful DoFn, a timer that fires and is buffered until the checkpoint completes is replayed with a null key.
  • Effect: @Key in @OnTimer is null for the replayed timer.
  • Cause: BufferedElements.Coder doesn't encode the key of a buffered timer. On decode it uses the coder's own key, and BufferingDoFnRunner creates that coder with a null key.

Tested on master 5d834f2781b, runner flink:1.19, JDK 17.

Where

  • BufferedElements.Coder.encode (BufferedElements.java, lines ~164-172): writes the timer's id, family, window, timestamps and time domain, but not its key.
  • BufferedElements.Coder.decode (line ~188): rebuilds the timer with the coder's own key.
  • BufferingDoFnRunner (line ~184): constructs the coder with a null key.

When it happens

The key is lost whenever a buffered timer goes through the coder:

Backend Restored from checkpoint Key in @OnTimer
RocksDB no null
RocksDB yes null
Heap yes null
Heap no correct

RocksDB always serializes state, so it hits this on every replay. The heap backend keeps the object in memory, so it only hits this after a restore.

Reproduction

A DoFnOperatorTest-style test: keyed @RequiresStableInput DoFn with an event-time timer whose @OnTimer method reads @Key. Process an element, complete a checkpoint, advance the watermark so the timer fires and is buffered, then complete the next checkpoint (optionally restoring from a snapshot in between). The timer fires once, but @Key is null.

Impact

  • Shown by tests: @Key in @OnTimer is null for buffered timers, on RocksDB always and on heap after restore.
  • From reading the code, not tested: @OnWindowExpiration likely gets a null key too.
  • Not checked: whether user code then fails (e.g. NPE or an encoding error); behaviour on a real cluster; the portable runner.

Related: #41512 (heap backend, wrong key context on replay), found at the same time. I have the reproducer test and can open a PR with it or a fix.

Found while working on #41448.

Issue Priority

Priority: 2 (default / most bugs should be filed as P2)

Issue Components

  • [ ] Component: Python SDK
  • [x] Component: Java SDK
  • [ ] Component: Go SDK
  • [ ] Component: Typescript SDK
  • [ ] Component: IO connector
  • [ ] Component: Beam YAML
  • [ ] Component: Beam examples
  • [ ] Component: Beam playground
  • [ ] Component: Beam katas
  • [ ] Component: Website
  • [ ] Component: Infrastructure
  • [ ] Component: Spark Runner
  • [ ] Component: Flink Runner
  • [ ] Component: Prism Runner
  • [ ] Component: Hazelcast Jet Runner
  • [ ] Component: Google Cloud Dataflow Runner

alisha-1000 avatar Nov 20 '26 17:11 alisha-1000

.add-labels flink,runners

alisha-1000 avatar Nov 20 '26 17:11 alisha-1000

.take-issue

alisha-1000 avatar Nov 20 '26 17:11 alisha-1000