ChickenBenny opened a new pull request, #77489:
URL: https://github.com/apache/airflow/pull/77489

   # Body
   
   * related: #74717
   * related: #76359
   * related: #76103 (TypeScript SDK)
   
   ---
   
   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 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]

Reply via email to