Skip to content

Commit b206c78

Browse files
committed
only check if thread is alive after cancelling it (#279)
it appears that in some cases, especially under high load, calling `.cancel()` will immediately stop the thread, making the `.join()` call fail. To avoid this, we first `cancel()`, then check `is_alive()` and only _then_ `join()` the thread. fixes #276 closes #279
1 parent 467d112 commit b206c78

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
* added "authorization" to list of sensitive keywords, to ensure that "Authorization"
1010
HTTP headers are properly sanitized (#275)
1111
* taught the Logbook handler how to handle the `stack=False` option (#278)
12+
* fixed a race condition with managing the timer-send thread (#279)
1213

1314
## v3.0.0
1415

elasticapm/base.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,9 +318,10 @@ def _start_send_timer(self, timeout=None):
318318
self._send_timer.start()
319319

320320
def _stop_send_timer(self):
321-
if self._send_timer and self._send_timer.is_alive() and not self._send_timer == threading.current_thread():
321+
if self._send_timer and not self._send_timer == threading.current_thread():
322322
self._send_timer.cancel()
323-
self._send_timer.join()
323+
if self._send_timer.is_alive():
324+
self._send_timer.join()
324325

325326
def _send_remote(self, url, data, headers=None):
326327
if headers is None:

0 commit comments

Comments
 (0)