Skip to content

Go SDK stop a task at its execution_timeout - #77489

Open
ChickenBenny wants to merge 1 commit into
apache:mainfrom
ChickenBenny:go-sdk-execution-timeout-context
Open

ChickenBenny wants to merge 1 commit into
apache:mainfrom
ChickenBenny:go-sdk-execution-timeout-context

Conversation

@ChickenBenny

@ChickenBenny ChickenBenny commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Follow-up to #76359, the Go part of #74717.

Since #76359 the Go runtime sends SetExecutionTimeout before the task runs, but it still gives the task no signal at the timeout. The task keeps running until the supervisor sends SIGTERM killed_task_cleanup_time (60 s by default) later. If the task then returns nil, it is recorded as success and its retries are skipped.

Changes

  • Once the supervisor has acknowledged SetExecutionTimeout, the runtime starts its own clock, so the supervisor's deadline starts no later than the runtime's, as for a Python task.
  • At the timeout the task's ctx is cancelled with the new sdk.ErrTaskTimeout as its cause. A task can check errors.Is(context.Cause(ctx), sdk.ErrTaskTimeout) to tell a timeout from a shutdown and decide what to clean up.
  • The task then has until it returns, or until the supervisor's SIGTERM, to clean up. The runtime has no timer of its own for this, so the cleanup time is killed_task_cleanup_time, the same as for Python and TypeScript tasks. Then the task fails with task timed out after N seconds, as RetryTask when should_retry is set.
  • A task that times out cannot succeed: what it returns after the timeout is ignored. A value it returns after the timeout is not pushed as its return_value XCom, since requests on a cancelled ctx fail.
  • A task that ignores its ctx is reported as timed out at the SIGTERM. The runtime then exits, which ends the task's goroutine.
  • A SIGTERM before the timeout works as before: the runtime waits for the task and reports its result.
  • TriggerDagRun tasks get the same timeout.
  • The Go SDK docs and the airflow package docs describe the timeout and sdk.ErrTaskTimeout.
With execution_timeout=10, killed_task_cleanup_time=60 Before After
Task honours ctx cancelled at 70 s by SIGTERM cancelled at 10 s, fails with the timeout
Task returns nil after ctx is cancelled success at 70 s, no retry fails with the timeout, retries apply
Task ignores ctx SIGKILL at 130 s, no reason timeout reported at 70 s
No execution_timeout unchanged unchanged

Not covered: the remaining timeout after a deferred task resumes (#75317), and the Java part of #74717.

Validation

  • New tests: a task that returns its ctx error or a value after the timeout fails with it (both should_retry values) and pushes no XCom; a task that ignores its ctx is reported at the supervisor's SIGTERM; a SIGTERM before the timeout keeps the task's own result; a TriggerDagRun task times out; secondsToDuration caps a value past the longest time.Duration. Without the change, the end-to-end and TriggerDagRun tests hang until their test timeout.
  • go test ./... in go-sdk passed; go test -race on pkg/execution and sdk passed; prek hooks passed on commit.

This branch has not been deployed

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant