Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions shared/logging/src/airflow_shared/logging/structlog.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import os
import re
import sys
import weakref
from collections.abc import Callable, Iterable, Mapping, Sequence
from functools import cache, cached_property, partial
from pathlib import Path
Expand Down Expand Up @@ -593,6 +594,17 @@ def is_atty():
text_output = cast("TextIO", output)
logger_factory = LoggerFactory(NamedWriteLogger, io=text_output)

# Replace structlog's WRITE_LOCKS dict with a WeakKeyDictionary so entries
# for closed file descriptors are garbage-collected instead of leaking.
# TODO: drop once structlog ships the upstream fix (tracked for 26.1.0).
try:
from structlog import _output as _structlog_output

if isinstance(_structlog_output.WRITE_LOCKS, dict):
_structlog_output.WRITE_LOCKS = weakref.WeakKeyDictionary() # type: ignore[assignment]
except Exception:
pass

structlog.configure(
processors=shared_pre_chain + [for_structlog],
cache_logger_on_first_use=cache_logger_on_first_use,
Expand Down
Loading