beam icon indicating copy to clipboard operation
beam copied to clipboard

[Feature Request]: Add the ability to cancel timers in methods annotated with @onWindowExpiration

Open slilichenko opened this issue 11 months ago • 1 comments

What would you like to happen?

Stateful DoFns which use looping timers in ProcessTime domain need to clear the timers in order for the pipeline to drain properly when running using Dataflow runner. The only way now to detect the pipeline drain event is by defining a method annotated with @onWindowExpiration.

The documentation here states that this method can take the same parameters as the method annotated with @OnTimer. But timer-related parameters are not allowed because there are not on the allow-list

The workaround is not complex - using a dedicated or some other state pointer, setting up the state to some value, clearing the state in the onWindowExpiration() and not setting the timer if the state is null, but it's not well known and adds unneeded complexity.

Issue Priority

Priority: 2 (default / most feature requests 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: Samza Runner
  • [ ] Component: Twister2 Runner
  • [ ] Component: Hazelcast Jet Runner
  • [ ] Component: Google Cloud Dataflow Runner

slilichenko avatar Jan 14 '25 21:01 slilichenko

This issue has been marked as stale due to 150 days of inactivity. It will be closed in 30 days if no further activity occurs. If you think that’s incorrect or this issue still needs to be addressed, please simply write any comment. If closed, you can reopen the issue at any time. Thank you for your contributions.

github-actions[bot] avatar Jun 14 '25 12:06 github-actions[bot]

Please keep it

slilichenko avatar Jun 16 '25 18:06 slilichenko

@OnWindowExpiration should not be called when there are any timers that could still fire. We have some limitations around this that are really bugs. But there is no sense to manually have the user or SDK cancel the timers. They should already be invalid (ignored on the backend) or fired.

kennknowles avatar Sep 24 '25 21:09 kennknowles

I'm going to close this as wontfix - this doesn't mean we won't address the underlying issue, which is needing a way to deal with looping timers in drain. I sent a doc to dev@beam that has some solutions a little while ago. I've gotten sidetracked and haven't sold the work to anyone else yet, but the element metadata needed to implement it is on its way soon.

kennknowles avatar Sep 24 '25 21:09 kennknowles