File handle-logger-flushing-already-closed-file-686.patch of Package venv-salt-minion
59
1
From e23dce108588a9c52d3f7542636892750d6efcbd Mon Sep 17 00:00:00 2001
2
From: Marek Czernek <marek.czernek@suse.com>
3
Date: Thu, 17 Oct 2024 15:52:00 +0200
4
Subject: [PATCH] Handle logger flushing already closed file (#686)
5
6
This is a partial cherry-pick of
7
https://github.com/saltstack/salt/commit/9683260d61668da8559ecde6caf63a52fedd8790
8
---
9
salt/_logging/handlers.py | 4 ++++
10
salt/_logging/impl.py | 10 +++++++++-
11
2 files changed, 13 insertions(+), 1 deletion(-)
12
13
diff --git a/salt/_logging/handlers.py b/salt/_logging/handlers.py
14
index 5a1a1613137..d8bc68a49db 100644
15
--- a/salt/_logging/handlers.py
16
+++ b/salt/_logging/handlers.py
17
18
super().__init__(stream)
19
self.__messages = deque(maxlen=max_queue_size)
20
self.__emitting = False
21
+ import traceback
22
+
23
+ self.stack = "".join(traceback.format_stack())
24
25
def handle(self, record):
26
self.acquire()
27
28
super().handle(record)
29
finally:
30
self.__emitting = False
31
+ # This will raise a ValueError if the file handle has been closed.
32
super().flush()
33
34
def sync_with_handlers(self, handlers=()):
35
diff --git a/salt/_logging/impl.py b/salt/_logging/impl.py
36
index 4d1ebd2495f..9d76c3174e2 100644
37
--- a/salt/_logging/impl.py
38
+++ b/salt/_logging/impl.py
39
40
break
41
else:
42
handler = DeferredStreamHandler(sys.stderr)
43
- atexit.register(handler.flush)
44
+
45
+ def tryflush():
46
+ try:
47
+ handler.flush()
48
+ except ValueError:
49
+ # File handle has already been closed.
50
+ pass
51
+
52
+ atexit.register(tryflush)
53
handler.setLevel(log_level)
54
55
# Set the default temporary console formatter config
56
--
57
2.47.0
58
59