Skip to content

airflow-webserver crashes if log files are larger than webserver available RAM #31105

Closed

Description

@getaaron

Apache Airflow version

2.6.0

What happened

I tried to view a 400MB dag log file in the web server UI.

The available RAM on the Kubernetes pod is 50MB.

The Airflow webserver crashed.

What you think should happen instead

Either

  1. The log file should be truncated and an error shown that there's not enough RAM, or
  2. The log file should not be fully realized into RAM and should be streamed to frontend instead

How to reproduce

  1. create airflow on k8s with 50Mi requested pod sizes
  2. make a dag that generates 400 megabyte log files
  3. attempt to view the log file in the airflow UI

Operating System

Debian GNU/Linux 11 (bullseye)

Versions of Apache Airflow Providers

apache-airflow==2.6.0
apache-airflow-providers-cncf-kubernetes==6.1.0
apache-airflow-providers-oracle==3.0.0
apache-airflow-providers-slack==7.2.0

Deployment

Official Apache Airflow Helm Chart

Deployment details

No response

Anything else

No response

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Activity

  1. added
    kind:bug
    needs-triage
    on May 5, 2023
  2. boring-cyborg commented on May 5, 2023

    @boring-cyborg

    Thanks for opening your first issue here! Be sure to follow the issue template! If you are willing to raise PR to address this issue please do so, no need to wait for approval.

  3. getaaron commented on May 5, 2023

    @getaaron
    ContributorAuthor

    Haven't worked in airflow before, I could potentially open a PR if someone can describe what the fix should be

  4. added and removed
    needs-triage
    on May 6, 2023
  5. potiuk commented on May 6, 2023

    @potiuk
    Member

    Haven't worked in airflow before, I could potentially open a PR if someone can describe what the fix should be

    I think you pretty well described it :) .

    What you think should happen instead
    Either

    The log file should be truncated and an error shown that there's not enough RAM, or
    The log file should not be fully realized into RAM and should be streamed to frontend instead

    One of those seems to be a good solution, just the place where airflow loads the file in memory has to be find and one of the solutions above appied (there are many different ways of loading logs - depending on the view you used and state of the task and log configuration (for example if there is remote logging or streaming it is different than when local logs are used and different when celery logs are used).

    I marked it as good-first-issue for you whoever would like to fix it , it's likely a bit more than first issue though and requires quite a bit of digging in the code, but if someone knows a bit about Python/webserver/flask it should not be that difficult to find the right place.

  6. getaaron commented on May 8, 2023

    @getaaron
    ContributorAuthor
  7. killua1zoldyck commented on Jun 20, 2023

    @killua1zoldyck
    Contributor

    @potiuk if no one's working on this and if this has not been fixed yet I can work on this.

  8. potiuk commented on Jun 20, 2023

    @potiuk
    Member

    Feel free!

  9. killua1zoldyck commented on Jun 23, 2023

    @killua1zoldyck
    Contributor

    @potiuk The current log-streaming logic pulls the whole file into memory before moving to the specific log_pos based on the metadata after combining all the logs and sorting them based on timestamp.

    logs = "\n".join(
    _interleave_logs(
    *local_logs,
    *remote_logs,
    *(executor_logs or []),
    *served_logs,
    )
    )
    log_pos = len(logs)
    messages = "".join([f"*** {x}\n" for x in messages_list])
    end_of_log = ti.try_number != try_number or ti.state not in [State.RUNNING, State.DEFERRED]
    if metadata and "log_pos" in metadata:
    previous_chars = metadata["log_pos"]
    logs = logs[previous_chars:] # Cut off previously passed log test as new tail
    out_message = logs if "log_pos" in (metadata or {}) else messages + logs
    return out_message, {"end_of_log": end_of_log, "log_pos": log_pos}

    So, I don't think we can change the logic to make it streaming. Is my thinking correct?

  10. potiuk commented on Jun 23, 2023

    @potiuk
    Member

    I have not looked at it befor so I have no idea. I was kind of hoping that whoever takes on the task will be able to propose the solution - possibly involving chnaging the way how it is done.

  11. 25 remaining items

  12. killua1zoldyck commented on Aug 23, 2023

    @killua1zoldyck
    Contributor

    Hi, @yatink I did implement the k way merge suggested (although there were a few issues with my implementation). I didn't notice that there was a resource log_endpoint.py and my implementation meant that it was to be changed.

  13. yatink commented on Aug 27, 2023

    @yatink

    @killua1zoldyck, can you put your k-way merge implementation into a gist (or similar) temporarily so that I can reference them ? If not, no worries.

  14. yatink commented on Aug 27, 2023

    @yatink

    The way that I'm thinking about solving this issue is to do so in 2 steps:

    1. First, stop the webserver from crashing and pop a reasonable error message instead
    2. Continue down the path that @killua1zoldyck had started and implement the k way merge to enable it to handle large log files

    I'm on the fence about whether they should be tracked as separate issues or not. I'll be able to give a more informed opinion after I've made more progress.

    @potiuk and/or @getaaron, let me know if step 1 is a reasonable short term approach or whether I should just skip it and do step 2.

  15. potiuk commented on Aug 28, 2023

    @potiuk
    Member

    @potiuk and/or @getaaron, let me know if step 1 is a reasonable short term approach or whether I should just skip it and do step 2.

    Yes. This is exactly how I would have imagined it too. It's quite likely as well that we will stop at task 1 if we find 2 too much of complexity. I have a feeling that trying to implement k-way merge sort in this case is not giving "the bang for the bucks". If you have such a huge log, finding anything meaningful in Airlfow UI for it will be next to impossible, search and everything there will also struggle if you try to scroll through it and you would likely have to implement a full-fledged search and likely other APIs to make use of such a huge log.

    In this case just posting a message "Your log is definitely too large to handle" and pointing the user to "Consider fine-tuning your tasks to make your logs smaller or configure remote logging and choose some dedicated logging solution such to store your logs" is quite likely 9X% of the effect with 1% of the effort.

  16. yatink commented on Sep 12, 2023

    @yatink

    Sorry for the delay, I got airflow on kube set up on my laptop, so I'm going to pick up this issue and attempt to implement option 1 👇🏽 .

    First, stop the webserver from crashing and pop a reasonable error message instead

    Do you all have any large dag files lying around, preferably one that's larger than 400MB ? 😄 That's all that I'm missing (in theory) to reproduce the issue.

  17. killua1zoldyck commented on Sep 12, 2023

    @killua1zoldyck
    Contributor

    Sorry for the delay, I got airflow on kube set up on my laptop, so I'm going to pick up this issue and attempt to implement option 1 👇🏽 .

    First, stop the webserver from crashing and pop a reasonable error message instead

    Do you all have any large dag files lying around, preferably one that's larger than 400MB ? 😄 That's all that I'm missing (in theory) to reproduce the issue.

    We can just have a PythonOperator that takes as an argument the size of logs that it has to produce and it can log, say 400 MB of random value.

  18. yatink commented on Sep 12, 2023

    @yatink

    Hmmm...it appears that I don't have the privs to assign this issue to myself. Can someone help me with that (either by giving me privs or assigning this issue to me directly) ?

  19. potiuk commented on Sep 12, 2023

    @potiuk
    Member

    Assigned. Good Luck :)

  20. mujiannan commented on Jan 7, 2024

    @mujiannan

    Even a small log file can destroy the gunicorn in webserver.
    Run a task in kubernetes, log to s3, then you will go into a `interleave' condition, viewing logs of the running task from webui cause a gunicorn "cpu 100%" and crashing soon.

  21. potiuk commented on Jan 7, 2024

    @potiuk
    Member

    Even a small log file can destroy the gunicorn in webserver. Run a task in kubernetes, log to s3, then you will go into a `interleave' condition, viewing logs of the running task from webui cause a gunicorn "cpu 100%" and crashing soon.

    If you can provide some actionable details - like size of your log for example details of memory allocated for your processes, then that would be much more actionable than "small log crashing server"

  22. potiuk commented on Jan 7, 2024

    @potiuk
    Member

    Also versiin of packages that causes it - would also be useful.

  23. jason810496 commented on Jul 17, 2025

    @jason810496
    Member

    Resolve OOM When Reading Large Logs in Webserver #49470 and its backport [v3-0-test] Resolve OOM When Reading Large Logs in Webserver #53167 have been merged, so this issue can now be closed as completed.

    The patch will be included in the next Airflow release, 3.0.4.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    _eol_affected_version:2.6area:loggingarea:webserverkind:bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions