damccorm opened a new pull request, #41627:
URL: https://github.com/apache/beam/pull/41627
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 :)
## Summary
Increases `WAIT_IN_STATE_TIMEOUT` in `TestDataflowRunner` from 10 minutes to
20 minutes and retries transient Dataflow `400 FailedPrecondition` errors in
`DataflowApplicationClient.modify_job_state`.
## Production Impact
This changes production code in `DataflowApplicationClient.modify_job_state`
(`sdks/python/apache_beam/runners/dataflow/internal/apiclient.py`), which backs
`DataflowPipelineResult.cancel()` and `drain()`. Previously, calling `cancel()`
while a newly created Dataflow job was still initializing (`'Job is not yet
ready for canceling'`) or during a brief control-plane backend reassignment
window (`'Job has no backend assigned'`) immediately failed with an unretried
`google.api_core.exceptions.FailedPrecondition`. With this change, those two
transient preconditions are retried with exponential backoff while terminal
`FailedPrecondition` errors (e.g., canceling an already terminated job) still
fail immediately without retrying.
## Root Cause
1. Under concurrent Dataflow job submissions in `apache-beam-testing`,
streaming Dataflow jobs can spend slightly more than 10 minutes in
`JOB_STATE_PENDING` before transitioning to `JOB_STATE_RUNNING`, tripping
`TestDataflowRunner.WAIT_IN_STATE_TIMEOUT = 10 * 60`.
2. When `TestDataflowRunner` (or any user code) cancels a job that is still
initializing or briefly unassigned to a workflow backend, the Dataflow
`update_job` API returns `400 FAILED_PRECONDITION` with `'not yet ready for
canceling'` or `'no backend assigned'`. `modify_job_state` used the default
`retry.retry_on_server_errors_filter`, which does not retry HTTP 400 /
`FailedPrecondition`.
## Fix
- Bump `WAIT_IN_STATE_TIMEOUT` in
`sdks/python/apache_beam/runners/dataflow/test_dataflow_runner.py` from `10 *
60` to `20 * 60`.
- Add `_retry_on_modify_job_state_error` in
`sdks/python/apache_beam/runners/dataflow/internal/apiclient.py` and pass it as
`retry_filter` on `DataflowApplicationClient.modify_job_state` to retry server
errors plus transient `FailedPrecondition` responses matching `'not yet ready
for canceling'` or `'no backend assigned'`.
- Add unit test
`UtilTest.test_modify_job_state_retries_transient_failed_precondition` in
`sdks/python/apache_beam/runners/dataflow/internal/apiclient_test.py` covering
both retryable messages and verifying non-transient `FailedPrecondition` errors
are not retried.
## Verification
- Ran `yapf --style setup.cfg --diff` across all 3 modified files (clean).
- Ran `pytest apache_beam/runners/dataflow/internal/apiclient_test.py
apache_beam/runners/dataflow/dataflow_runner_test.py` locally (101 passed, 2
skipped).
### Recent Occurrences
4 failing `master` workflow runs in the past 3 weeks:
- `PostCommit Python ValidatesRunner Dataflow` (3 runs):
- https://github.com/apache/beam/actions/runs/44419294495 (2026-11-18)
- https://github.com/apache/beam/actions/runs/44781679460 (2026-11-20)
- https://github.com/apache/beam/actions/runs/45048509302 (2026-11-22)
- `PostCommit Python` (1 run, `'Job has no backend assigned'` on cancel):
- https://github.com/apache/beam/actions/runs/45017830863 (2026-11-22)
--
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]