Skip to content

Commit

Permalink
Resolve handler close race condition at triggerer shutdown (#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.

(cherry picked from commit e24f0a9)
  • Loading branch information
dstandish authored and ephraimbuddy committed Feb 20, 2024
1 parent da72fae commit defaaef
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions airflow/utils/log/trigger_handler.py
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 defaaef

Please sign in to comment.