Skip to content

Read the AWS task logs once more after the fetcher is stopped - #73211

Merged
o-nikolas merged 2 commits into
apache:mainfrom
fpiped:fix/ecs-log-fetcher-tail
Sep 28, 2026
Merged

o-nikolas merged 2 commits into
apache:mainfrom
fpiped:fix/ecs-log-fetcher-tail

Conversation

@fpiped

@fpiped fpiped commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

AwsTaskLogFetcher.run checks the stop flag at the top of its loop, then sleeps, then fetches. When stop() arrives while the thread is inside a fetch, or in the gap between a fetch finishing and the next check, the loop ends with no read after the stop, and the events the container wrote at the end of the task are never forwarded to the task log.

Both callers stop the fetcher as soon as the task or job has ended, which is exactly when those events appear: EcsRunTaskOperator.execute (finally: self.task_log_fetcher.stop()) and BatchClientHook.wait_for_job (finally: batch_log_fetcher.stop()).

This forwards the events once more after leaving the loop. The continuation token keeps the extra read from repeating events already seen, and AwsLogsHook.get_log_events returns as soon as the stream is exhausted, so the cost is one get_log_events call at thread exit. The body of the loop moved into _forward_log_events unchanged.

test_run_forwards_the_events_written_before_it_was_stopped covers it: it fails on the current code (one fetch, the last event never logged) and passes here. The two existing run tests each get one more empty page in their side_effect, since run now always performs that final fetch.

Verified locally with apache-airflow 3.1.8 and the provider installed from this branch:

providers/amazon/tests/unit/amazon/aws/utils/test_task_log_fetcher.py   32 passed
ruff check / ruff format --check on both files                          clean

tests/unit/amazon/aws/operators/test_ecs.py, test_batch.py and hooks/test_batch_client.py patch AwsTaskLogFetcher as a whole and never exercise run, so they are unaffected; CI runs them.

closes: #73210


Was generative AI tooling used to co-author this PR?
  • Yes (please specify the tool below)

Generated-by: Claude Code following the guidelines

The behaviour was reproduced against the released provider before the change, the fix and its test were reviewed line by line, and the tests and static checks above were run locally.

`AwsTaskLogFetcher.run` checks the stop flag at the top of its loop, so a
`stop()` that arrives while the thread is inside a fetch, or between a fetch
and the next check, ends the loop with no read after it. The events the
container wrote at the end of the task are then never forwarded to the task
log. `EcsRunTaskOperator.execute` and `BatchClientHook.wait_for_job` both
stop the fetcher as soon as the task or job has ended, which is exactly when
those last events appear.

Forward the events once more after leaving the loop. The continuation token
keeps that read from repeating events already seen.

closes: apache#73210
Comment thread providers/amazon/src/airflow/providers/amazon/aws/utils/task_log_fetcher.py Outdated
Wait on the stop event instead of sleeping for fetch_interval, so stop()
ends the wait at once and the final read runs without the extra delay.
@o-nikolas
o-nikolas merged commit 10221c3 into apache:main Sep 28, 2026
83 checks passed
@boring-cyborg

boring-cyborg Bot commented Sep 28, 2026

Copy link
Copy Markdown

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:amazon AWS/Amazon - related issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AwsTaskLogFetcher can exit without reading the log events written at the end of an ECS task or Batch job

2 participants