Skip to content

Commit

Permalink
Resolve handler close race condition at triggerer shutdown (apache#37206
Browse files Browse the repository at this point in the history
)

At shutdown, a trigger may emit a "close" signal around the same time as logging.shutDown is called, so the handler may have been removed from the handlers by one thread when the other tries to delete it.
  • Loading branch information
dstandish authored and abhishekbhakat committed Mar 5, 2024
1 parent de41609 commit 43a674c
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions airflow/utils/log/trigger_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import asyncio
import logging
from contextlib import suppress
from contextvars import ContextVar
from copy import copy
from logging.handlers import QueueHandler
Expand Down Expand Up @@ -110,17 +111,16 @@ def close_one(self, trigger_id):
h = self.handlers.get(trigger_id)
if h:
h.close()
del self.handlers[trigger_id]
with suppress(KeyError): # race condition between `handle` and `close`
del self.handlers[trigger_id]

def flush(self):
for h in self.handlers.values():
h.flush()

def close(self):
for trigger_id in list(self.handlers.keys()):
h = self.handlers[trigger_id]
h.close()
del self.handlers[trigger_id]
self.close_one(trigger_id)


class LocalQueueHandler(QueueHandler):
Expand Down

0 comments on commit 43a674c

Please sign in to comment.