forked from apache/beam
-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix Race Condition in removeReadyTimers() to Prevent Cleared Timers from Firing #143
Merged
xinyuiscool
merged 2 commits into
linkedin:li_trunk
from
FuRyanf:FuRyanf/cleared-timers-firing-bug
Mar 1, 2025
Merged
Fix Race Condition in removeReadyTimers() to Prevent Cleared Timers from Firing #143
xinyuiscool
merged 2 commits into
linkedin:li_trunk
from
FuRyanf:FuRyanf/cleared-timers-firing-bug
Mar 1, 2025
+121
−28
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
xinyuiscool
reviewed
Feb 19, 2025
runners/samza/src/main/java/org/apache/beam/runners/samza/runtime/DoFnOp.java
Outdated
Show resolved
Hide resolved
...rs/samza/src/main/java/org/apache/beam/runners/samza/runtime/SamzaTimerInternalsFactory.java
Outdated
Show resolved
Hide resolved
Please do a ./gradlew :runners:samza:validatesRunner so we can run through all beam timer test cases. Thanks. |
xinyuiscool
reviewed
Feb 19, 2025
...rs/samza/src/main/java/org/apache/beam/runners/samza/runtime/SamzaTimerInternalsFactory.java
Outdated
Show resolved
Hide resolved
c292981
to
f2ce6c0
Compare
f2ce6c0
to
8432257
Compare
8432257
to
0d194c0
Compare
0d194c0
to
e364c9c
Compare
xinyuiscool
reviewed
Feb 26, 2025
...rs/samza/src/main/java/org/apache/beam/runners/samza/runtime/SamzaTimerInternalsFactory.java
Show resolved
Hide resolved
d5649cf
to
8407aa7
Compare
8407aa7
to
d858e1f
Compare
xinyuiscool
approved these changes
Mar 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! Thanks for the update. One minor comment.
...rs/samza/src/main/java/org/apache/beam/runners/samza/runtime/SamzaTimerInternalsFactory.java
Show resolved
Hide resolved
5b0b671
to
0717427
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue Summary
A race condition in
removeReadyTimers()
allows timers that were cleared in the same batch to still fire. This occurs because the method loads timers intoeventTimeBuffer
in batches, and if an earlier timer clears a later timer, the later timer is still added toreadyTimers
. However, sincestate.get(timerKey, timeDomain)
returnsnull
(or0
) after deletion, it fails to be properly removed, leading to it firing incorrectly when it should have been cleared.Root Cause
removeReadyTimers()
removes timers fromeventTimeBuffer
and adds them toreadyTimers
.state.deletePersisted(keyedTimerData)
.state.get(timerKey, timeDomain)
returnnull
.readyTimers
, leading to it firing when it should have been cleared.Proposed Solution
To address this race condition, we have consolidated the removal and firing logic into a single method,
fireReadyTimers()
, ensuring that timers are verified in persistent state before being fired. The updated approach works as follows:eventTimeBuffer
without immediately deleting them from persistent state.state.get(timerKey, timeDomain)
. If it still exists in persistent state and its stored timestamp matches, it is deleted and fired.removeReadyTimers()
function was eliminated, and all related calls (e.g., inDoFnOp
,GroupByKeyOp
, andSplittableParDoProcessKeyedElementsOp
) were updated to usefireReadyTimers()
.Code Changes:
fireReadyTimers()
inSamzaTimerInternalsFactory
, replacingremoveReadyTimers()
.DoFnOp
,GroupByKeyOp
, andSplittableParDoProcessKeyedElementsOp
to invokefireReadyTimers()
instead of handling timers separately.SamzaTimerInternalsFactoryTest
to verify thatfireReadyTimers()
correctly processes and fires timers while ensuring that cleared timers are not fired.Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:
addresses #123
), if applicable. This will automatically add a link to the pull request in the issue. If you would like the issue to automatically close on merging the pull request, commentfixes #<ISSUE NUMBER>
instead.CHANGES.md
with noteworthy changes.See the Contributor Guide for more tips on how to make review process smoother.
To check the build health, please visit https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md
GitHub Actions Tests Status (on master branch)
See CI.md for more information about GitHub Actions CI.