damccorm opened a new pull request, #41903:
URL: https://github.com/apache/beam/pull/41903
Note: this PR was auto-generated by tooling. Before moving it out of draft,
the author has done a full review of the PR, specifically evaluating it on the
following criteria:
- The PR is an appropriate fix for the issue (e.g. we're not changing a test
to avoid a bug)
- The PR is a simple fix to the issue (e.g. we're not adding infra when we
could just modify a test)
- The PR is not covering for other problems (e.g. if we're bumping timeouts,
it is not because we're covering for a performance problem)
Full details of the methodology of generation and review can be found here -
https://docs.google.com/document/d/14lj7ECVov4T4EdwmIzNlWrRGE3lLDMOwX5xUMGzaLoc/edit?usp=sharing
If you have concerns with the PR or with the underlying methodology used to
generate this, please comment below - they will be addressed by the author not
the tooling :)
## Root Cause
In `PreCommit Java GCP IO Direct` runs
[46954070342](https://github.com/apache/beam/actions/runs/46954070342) ([build
scan](https://develocity.apache.org/s/jzslltdt4dpsa)) and
[47111889045](https://github.com/apache/beam/actions/runs/47111889045) ([build
scan](https://develocity.apache.org/s/b7udxljx7whpw)),
`BigQueryIOWriteStorageApiStreamTest.testStorageWriteReturnsAppendSerializationError[useStorageApi=true,
useStorageApiApproximate=true, useStreaming=true]` hung silently for 600
seconds inside `DirectRunner.waitUntilFinish()` until JUnit timed out.
The bug is in `DirectRunner`'s
`WatermarkManager.SynchronizedProcessingTimeInputWatermark.updateTimers`
(introduced when PR #16928 copied event-time `updateTimers` logic without
accounting for differences in `SynchronizedProcessingTimeInputWatermark`):
1. **Dropped re-armed identical timers (deadlock)**: When a
`PROCESSING_TIME` or `SYNCHRONIZED_PROCESSING_TIME` timer fires,
`extractFiredDomainTimers` removes it from `timerQueue` (`processingTimers` /
`synchronizedProcessingTimers`) and adds it to `pendingTimers`, while leaving
it in `existingTimersForKey`. If the timer callback completes and re-sets a
timer with the same `stringKey()` and identical timestamp/outputTimestamp (so
`existingTimer.equals(addedTimer)` is `true`), `updateTimers` took the `// else
the timer is already set identically, so noop` branch and **never re-added the
timer to `timerQueue`**. Because `DirectRunner` uses `NanosOffsetClock` while
`PeriodicSequenceFn` (the SDF behind `PeriodicImpulse`, used with 1ms intervals
in `testStorageWriteReturnsAppendSerializationError`) computes resume delays
against `Instant.now()`, a 1ms phase difference can cause
`SplittableParDoViaKeyedWorkItems.ProcessFn` to re-arm its anonymous
`PROCESSING_TIME` resume timer with the
exact same millisecond timestamp — permanently losing the resume timer and
deadlocking the pipeline. (Note: `AppliedPTransformInputWatermark.updateTimers`
for `EVENT_TIME` already avoids this by unconditionally removing and re-adding
`timer` to `keyTimers`.)
2. **Leaked `pendingTimers` entries on timer reset**: Unlike
`AppliedPTransformInputWatermark.pendingTimers` (which tracks both unfired and
fired timers), `SynchronizedProcessingTimeInputWatermark.pendingTimers` tracks
**only fired, in-flight timers** waiting for completion. Guarding
`pendingTimers.remove(completedTimer)` behind `if
(!newSetTimers.contains(timerKey))` prevented a completed timer from being
removed from `pendingTimers` whenever the callback re-set a timer with the same
`stringKey()` (even at a later timestamp), pinning
`getEarliestTimerTimestamp()` and downstream synchronized processing time at
the completed timer's timestamp indefinitely.
## Fix
- In `SynchronizedProcessingTimeInputWatermark.updateTimers`,
unconditionally remove any `existingTimer` from `timerQueue` and add
`addedTimer` to `timerQueue` (matching
`AppliedPTransformInputWatermark.updateTimers`), so re-armed identical
processing-time timers are re-enqueued after firing.
- Always remove non-`EVENT_TIME` `completedTimer` entries from
`pendingTimers` (while keeping the `!newSetTimers.contains(timerKey)` guard on
`existingTimersForKey.remove(timerKey)`).
- Add regression unit tests in `WatermarkManagerTest` covering both
re-arming a fired processing-time timer with an identical timestamp and
advancing downstream synchronized processing time when a fired processing-time
timer is reset to a later timestamp.
### Verification
- Triggered `.github/workflows/beam_PreCommit_Java_GCP_IO_Direct.yml`
workflow run on branch:
[`47126759446`](https://github.com/apache/beam/actions/runs/47126759446)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]