Fix memory leak in forked worker caused by unreleased file descriptor locks#65121
Open
wjddn279 wants to merge 1 commit intoapache:mainfrom
Open
Fix memory leak in forked worker caused by unreleased file descriptor locks#65121wjddn279 wants to merge 1 commit intoapache:mainfrom
wjddn279 wants to merge 1 commit intoapache:mainfrom
Conversation
6f0717f to
ad37cd0
Compare
eladkal
reviewed
Apr 13, 2026
| import psutil | ||
| import structlog | ||
| from pydantic import BaseModel, TypeAdapter | ||
| from structlog._output import WRITE_LOCKS |
Contributor
There was a problem hiding this comment.
importing private modules from upstream library is probably not something we want to do
Contributor
Author
There was a problem hiding this comment.
I've made pr for handling it in structlog library hynek/structlog#806.
I can't confirm it could be accepted and merged, but there is no other way to resolving this issue
Member
There was a problem hiding this comment.
Yeah, we shouldn't really do this. If we correctly close/delete the structlog objects it should handle this for us.
Doing it this way feels liek papering over the problem?
9 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem?
We conducted an investigation to resolve the continuous memory growth in the Local Executor's forked processes, following the previous memory spike fix.
Using memray to profile the Local Executor's forked processes, we confirmed that memory was steadily increasing. Specifically, logging-related memory was growing, and this was traced to the process of writing to local files.
memray-flamegraph-output-2026-04-11 13:17:18.516888.html
Cause?
Looking at,
full_path.touch(new_file_permissions)conf.get("logging", "file_task_handler_new_file_permissions", fallback="0o664")in flamegraph, I noticed that basic string objects were not being properly garbage collected, which led us to suspect unreleased references.Upon examining
self._lock = _get_lock_for_file(self._file)in the memory-increasing area, I found that file descriptors were being cached as locks in a dictionary with no corresponding release mechanism. This prevented the file descriptors from being properly released, and consequently, the parent Process objects also retained references and were never garbage collected.Solution
After adding code to manually release these references, we re-ran the profiling and confirmed that the related objects were being properly freed.
memray-flamegraph-output-2026-04-12 13:14:12.556546.html
PS
The remained
parsed = [sys.intern(str(x)) for x in rel.split(sep) if x and x != '.']issue will be addressed in a separate PR.Was generative AI tooling used to co-author this PR?
{pr_number}.significant.rst, in airflow-core/newsfragments. You can add this file in a follow-up commit after the PR is created so you know the PR number.