Skip to content

Commit 97c7405

Browse files
authored
DTIN-6259: AutoFlushingRotatingUniqueFileHandler lock fix (#1341)
1 parent cd69554 commit 97c7405

File tree

1 file changed

+18
-23
lines changed

1 file changed

+18
-23
lines changed

scalyr_agent/monitor_utils/auto_flushing_rotating_unique_file_handler.py

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -93,29 +93,15 @@ def __init__(
9393
self._timer = None
9494

9595
def flush(self):
96-
if self._flush_delay <= 0:
97-
self._flush()
98-
99-
else:
100-
self._lock.acquire()
101-
try:
102-
if self._timer is not None:
103-
self._timer = threading.Timer(self._flush_delay, self._flush)
104-
self._timer.start()
105-
finally:
106-
self._lock.release()
107-
108-
def _flush(self):
109-
self._current_file.flush()
96+
pass
11097

111-
if self._flush_delay > 0:
112-
self._lock.acquire()
113-
try:
114-
if self._timer is not None:
115-
self._timer.cancel()
116-
self._timer = None
117-
finally:
118-
self._lock.release()
98+
def _delayed_flush(self):
99+
self._lock.acquire()
100+
try:
101+
self._current_file.flush()
102+
self._timer = None
103+
finally:
104+
self._lock.release()
119105

120106
def close(self):
121107
if self._flush_delay > 0:
@@ -147,7 +133,16 @@ def emit(self, record):
147133

148134
# NB The newline is automatically converted according to the platform
149135
self._current_file.write(self.format(record) + "\n")
150-
self.flush()
136+
137+
if self._flush_delay <= 0:
138+
self._current_file.flush()
139+
else:
140+
if self._timer is None:
141+
self._timer = threading.Timer(
142+
self._flush_delay, self._delayed_flush
143+
)
144+
self._timer.start()
145+
151146
self._current_size += size
152147
finally:
153148
self._lock.release()

0 commit comments

Comments
 (0)