Skip to content

Fix Cloud Run deferrable trigger handling of transient grpc errors#67219

Merged
shahar1 merged 1 commit into
apache:mainfrom
akshetpandey:akshetpandey/fix-cloud-run-trigger-transient-grpc
May 30, 2026
Merged

Fix Cloud Run deferrable trigger handling of transient grpc errors#67219
shahar1 merged 1 commit into
apache:mainfrom
akshetpandey:akshetpandey/fix-cloud-run-trigger-transient-grpc

Conversation

@akshetpandey
Copy link
Copy Markdown
Contributor

@akshetpandey akshetpandey commented May 20, 2026

related: #66293

Problem

CloudRunJobFinishedTrigger.run() polls the long-running operation via
CloudRunAsyncHook.get_operation in its loop. When that gRPC call fails
with a transient error — typical of a regional Cloud Run API blip while
the underlying job is still progressing fine — the exception
propagates out of the trigger:

  1. The triggerer logs the failure and tears down the trigger.
  2. The deferred task fails with TaskDeferralError.
  3. The worker's task-level retry re-runs the operator from scratch,
    which submits a brand new Cloud Run execution rather than
    waiting on the in-flight one. So a 1-second transient API blip turns
    into a duplicate (and billed) job run.

This mirrors the same class of bug fixed for Dataflow in #66293.

How to fix

Catch the full set of retryable gRPC errors inside the Cloud Run
get-operation polling loop, log a warning, sleep
polling_period_seconds, and continue polling. The retryable tuple is:

  • ServiceUnavailable (503 / UNAVAILABLE)
  • InternalServerError (500 / INTERNAL)
  • DeadlineExceeded (504 / DEADLINE_EXCEEDED)
  • GatewayTimeout
  • ResourceExhausted (429 / RESOURCE_EXHAUSTED)
  • Aborted

Anything outside that tuple (PermissionDenied, NotFound, auth
failures, unexpected RuntimeErrors) still propagates, so Airflow's
task-level retry remains the safety net for genuinely terminal
failures.

Tests

uv run --project providers/google pytest providers/google/tests/unit/google/cloud/triggers/test_cloud_run.py -xvs

Two parametrized tests cover the new behavior:

  • test_trigger_continues_polling_after_retryable_grpc_error — runs
    once per entry in the retryable tuple. The first get_operation
    raises the parametrized exception; the second returns a successfully
    completed operation. The trigger must yield the SUCCESS
    TriggerEvent and asyncio.sleep must be awaited exactly once with
    polling_period_seconds.
  • test_trigger_propagates_unexpected_polling_exception
    parametrized over PermissionDenied and a bare RuntimeError. Both
    must still propagate out of run(), locking in that only the
    retryable tuple is swallowed.

All pre-existing tests in test_cloud_run.py continue to pass.


Was generative AI tooling used to co-author this PR?
  • Yes (please specify the tool below)
    Generated-by: Claude Opus 4.7 following the guidelines

Copilot AI review requested due to automatic review settings May 20, 2026 00:37
@akshetpandey akshetpandey requested a review from shahar1 as a code owner May 20, 2026 00:37
@boring-cyborg boring-cyborg Bot added area:providers provider:google Google (including GCP) related issues labels May 20, 2026
@boring-cyborg
Copy link
Copy Markdown

boring-cyborg Bot commented May 20, 2026

Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contributors' Guide
Here are some useful points:

  • Pay attention to the quality of your code (ruff, mypy and type annotations). Our prek-hooks will help you with that.
  • In case of a new feature add useful documentation (in docstrings or in docs/ directory). Adding a new operator? Check this short guide Consider adding an example Dag that shows how users should use it.
  • Consider using Breeze environment for testing locally, it's a heavy docker but it ships with a working Airflow and a lot of integrations.
  • Be patient and persistent. It might take some time to get a review or get the final approval from Committers.
  • Please follow ASF Code of Conduct for all communication including (but not limited to) comments on Pull Requests, Mailing list and Slack.
  • Be sure to read the Airflow Coding style.
  • Always keep your Pull Requests rebased, otherwise your build might fail due to changes not related to your commits.
    Apache Airflow is a community-driven project and together we are making it better 🚀.
    In case of doubts contact the developers at:
    Mailing List: dev@airflow.apache.org
    Slack: https://s.apache.org/airflow-slack

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds resilience to the Cloud Run job-finished trigger by retrying transient Cloud Run API 503s during polling, preventing deferred tasks from failing and re-submitting jobs unnecessarily.

Changes:

  • Retry get_operation polling when google.api_core.exceptions.ServiceUnavailable occurs.
  • Add unit tests to verify retry-on-503 behavior and propagation of non-retryable exceptions.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
providers/google/src/airflow/providers/google/cloud/triggers/cloud_run.py Catch and retry ServiceUnavailable during operation polling with a logged warning and sleep.
providers/google/tests/unit/google/cloud/triggers/test_cloud_run.py Add tests covering retryable 503 behavior and non-retryable exception propagation.

Comment thread providers/google/tests/unit/google/cloud/triggers/test_cloud_run.py
Comment thread providers/google/tests/unit/google/cloud/triggers/test_cloud_run.py
Comment thread providers/google/src/airflow/providers/google/cloud/triggers/cloud_run.py Outdated
@akshetpandey akshetpandey changed the title Fix Cloud Run deferrable trigger handling of transient 503 Fix Cloud Run deferrable trigger handling of transient grpc errors May 20, 2026
Comment thread providers/google/tests/unit/google/cloud/triggers/test_cloud_run.py
@akshetpandey akshetpandey force-pushed the akshetpandey/fix-cloud-run-trigger-transient-grpc branch from 6c5bd38 to d162324 Compare May 22, 2026 20:03
@akshetpandey akshetpandey requested a review from shahar1 May 22, 2026 20:07
The CloudRunJobFinishedTrigger polls the long-running operation via
CloudRunAsyncHook.get_operation in its loop. When that gRPC call fails
with a transient 503 ServiceUnavailable — typical of a regional Cloud
Run API blip while the underlying job is still progressing — the
exception propagates out of the trigger, the triggerer logs the
failure, and the deferred task is failed with TaskDeferralError. The
worker's task-level retry then re-runs the operator from scratch,
which re-submits a brand new Cloud Run execution rather than waiting
on the in-flight one.

Catch ServiceUnavailable inside the polling loop, log a warning, sleep
polling_period_seconds, and continue — mirroring the equivalent fix in
DataflowJobStatusTrigger (apache#66293). Other exceptions still propagate so
Airflow's task-level retry can take over for genuinely terminal
errors.

Tests cover the new retry behavior (one ServiceUnavailable followed
by a successful poll yields the SUCCESS TriggerEvent) and lock in
that unexpected exceptions are not silently swallowed.

Signed-off-by: Akshet Pandey <argetlam.akshet@gmail.com>
@akshetpandey akshetpandey force-pushed the akshetpandey/fix-cloud-run-trigger-transient-grpc branch from 8c8c77c to bdd4389 Compare May 26, 2026 16:44
@akshetpandey
Copy link
Copy Markdown
Contributor Author

akshetpandey commented May 28, 2026

@shahar1 Updated the PR to address your comments

Copy link
Copy Markdown
Contributor

@shahar1 shahar1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@shahar1 shahar1 merged commit 29ac7c0 into apache:main May 30, 2026
94 checks passed
@boring-cyborg
Copy link
Copy Markdown

boring-cyborg Bot commented May 30, 2026

Awesome work, congrats on your first merged pull request! You are invited to check our Issue Tracker for additional contributions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:providers provider:google Google (including GCP) related issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants