You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
airflow-webserver crashes if log files are larger than webserver available RAM #31105
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.
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.
@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.
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.
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.
The way that I'm thinking about solving this issue is to do so in 2 steps:
First, stop the webserver from crashing and pop a reasonable error message instead
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.
@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.
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.
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.
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) ?
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.
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"
Activity
boring-cyborg commentedon May 5, 2023
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.
getaaron commentedon May 5, 2023
Haven't worked in airflow before, I could potentially open a PR if someone can describe what the fix should be
potiuk commentedon May 6, 2023
I think you pretty well described it :) .
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.
getaaron commentedon May 8, 2023
killua1zoldyck commentedon Jun 20, 2023
@potiuk if no one's working on this and if this has not been fixed yet I can work on this.
potiuk commentedon Jun 20, 2023
Feel free!
killua1zoldyck commentedon Jun 23, 2023
@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.
airflow/airflow/utils/log/file_task_handler.py
Lines 334 to 350 in 24e3d6c
So, I don't think we can change the logic to make it streaming. Is my thinking correct?
potiuk commentedon Jun 23, 2023
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.
25 remaining items
killua1zoldyck commentedon Aug 23, 2023
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.
yatink commentedon Aug 27, 2023
@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.
yatink commentedon Aug 27, 2023
The way that I'm thinking about solving this issue is to do so in 2 steps:
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.
potiuk commentedon Aug 28, 2023
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.
yatink commentedon Sep 12, 2023
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 👇🏽 .
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.
killua1zoldyck commentedon Sep 12, 2023
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.
yatink commentedon Sep 12, 2023
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) ?
potiuk commentedon Sep 12, 2023
Assigned. Good Luck :)
mujiannan commentedon Jan 7, 2024
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.
potiuk commentedon Jan 7, 2024
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"
potiuk commentedon Jan 7, 2024
Also versiin of packages that causes it - would also be useful.
jason810496 commentedon Jul 17, 2025
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.