Servers, nginx and Docker · Decision guide
Airflow task log page says Could not read served logs
Short answer
The API server could not download a task log from the small log server on the worker (port 8793) or the triggerer (8794). A 403 hint about secret_key means the components sign with different [api] secret_key values or their clocks drift. A connection or name error means the hostname the worker recorded cannot be reached from the API server.
Until a task's log is uploaded somewhere central, it lives on the machine that ran it. Airflow's logging documentation says a small HTTP server serves those files: the scheduler runs it under LocalExecutor, each Celery worker runs it under CeleryExecutor, and the triggerer runs its own for deferred tasks. When you open a log in the UI, the API server builds a URL from the hostname stored with the task attempt and asks that server for the file.
The message appears when that request fails. What follows it on the log page says which part failed, so start by copying the exact text, then pick your case below.
Find your case
- If the page shows the
!!!! Please make sure that all your Airflow components ... same 'secret_key'hintThe log server answered 403: the signed request was rejected. - If the text says
Hostname not availableand mentionshostname_callableNo hostname was stored for the attempt, so there was no URL to call. - If the text after the colon is a connection, timeout or name-resolution errorA hostname exists but the API server cannot reach it on the log port.
- If the page says
Log file not found on workerinsteadThe request worked; the file is not on that machine. - If only deferred tasks (sensors in deferrable mode) failThose logs come from the triggerer on its own port.
How the API server asks for a log
In file_task_handler.py the request is a plain GET to http://<hostname>:<port>/log/<relative path>, where the port is [logging] worker_log_server_port (default 8793). It carries a JWT signed with HS512 using [api] secret_key, with the audience task-instance-logs and a lifetime that falls back to 30 seconds. The wait for the first response is [api] log_fetch_timeout_sec, 5 seconds by default.
That gives three things that must line up between machines: the same secret, clocks within that short lifetime of each other, and a hostname plus port that the API server can actually open.
A 403 from the log server
On a 403 the handler prints only the !!!! hint, so you may not see the words "Could not read served logs" at all. The configuration reference explains why it happens: the same key that runs the API server authorizes log requests to workers, the token expires quickly, and machines with unsynchronized clocks get forbidden errors.
The mismatched key is the usual case. If nobody sets secret_key, its default is a placeholder that Airflow fills with random bytes (configuration.py builds it from os.urandom). A worker image or host that generated its own config therefore signs and checks with a key nobody else has.
Compare without printing the secret, then set one value
# on the API server, scheduler and every worker: the hashes must match
airflow config get-value api secret_key | sha256sum
date -u
# set one value everywhere (env var, or secret_key_cmd from a secrets store)
AIRFLOW__API__SECRET_KEY=<one shared random value>- Restart every component after the change; the key is read at start-up.
- If the hashes already match, compare
date -uacross hosts. A worker more than a few seconds off is enough, given a 30-second token.
No hostname recorded
If the stored hostname for the attempt is empty, the handler does not try the network at all and prints Hostname not available with a pointer to hostname_callable. That setting in [core] names a function returning the hostname; the default is airflow.utils.net.getfqdn. A custom callable that returns an empty string or None on some hosts produces exactly this.
Run on the worker that ran the task
airflow config get-value core hostname_callable
python -c "from airflow.utils.net import get_hostname; print(repr(get_hostname()))"The API server cannot reach the worker
Here a hostname exists, but requests raised an error trying to use it: the name does not resolve on the API server, nothing listens on the port, a firewall drops it, or the 5-second handshake wait runs out. Run the same request from where the API server runs, inside its container if it has one. Any HTTP status back, even 403, proves the path works.
From the API server host or container
curl -sS -m 5 -o /dev/null -w '%{http_code}\n' http://<worker-host>:8793/log/The name only means something on the worker
getfqdn returns what the worker thinks it is called. A container ID, a cloud-internal name or a laptop's .local name may not resolve elsewhere. The configuration reference offers airflow.utils.net.get_host_ip_address as the value for hostname_callable when you prefer the IP. Set it on the workers and restart; only attempts that start afterwards record the new value, so test with a fresh run.
The port is closed between them
The reference describes worker_log_server_port as a port that must be unused and reachable from the main web server. Open 8793 (or your value) from the API server to every worker, and to the scheduler host under LocalExecutor. In Docker Compose, the services must share a network; publishing the port to the host is not needed for container-to-container traffic.
Reached the worker but no file
A 404 is a different problem with its own message. The handler first tries the local disk of the API server; if the file is not there either, it says Log file not found on worker and suggests remote logging, because the attempt may have run on a worker that has since been replaced or cleaned up. None of the fixes above change that; durable storage does.
Logs from the triggerer
For an attempt that was deferred, the URL uses the triggerer's hostname and [logging] trigger_log_server_port, default 8794. The logging documentation notes that the triggerer serves logs unless it was started with --skip-serve-logs. Check that flag, the 8794 path and the triggerer's clock and key the same way as for a worker.
In short
- Copy the text after the message; it names the failing step.
- 403 hint: one [api] secret_key on every component and synchronized clocks.
- Hostname not available: fix hostname_callable on the worker.
- Connection or DNS errors: make the recorded name and port 8793 reachable from the API server.
- Remote logging removes the dependency on workers for finished tasks.
Sources
- Airflow: logging for tasks (serving logs from workers and triggerer)
- Airflow source 3.4.0: file_task_handler.py
- Airflow: configuration reference (secret_key, worker_log_server_port, hostname_callable)
- Airflow source 3.4.0: utils/net.py
- Airflow source 3.4.0: configuration.py (default SECRET_KEY)
- Airflow: CLI reference (config get-value)
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.