Skip to content

Commit

Permalink
Catch and log any exceptions while closing the transport
Browse files Browse the repository at this point in the history
Previously these would show up as big tracebacks in the logs which
was ugly, considering all sorts of things can go wrong when suddenly
closing the transport (such as when a celery worker terminates)

Fixes elastic#823
  • Loading branch information
basepi committed May 27, 2020
1 parent fdb27d6 commit 9c79c89
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions elasticapm/transport/base.py
Expand Up @@ -70,7 +70,7 @@ def __init__(
queue_chill_count=500,
queue_chill_time=1.0,
processors=None,
**kwargs
**kwargs,
):
"""
Create a new Transport instance
Expand Down Expand Up @@ -132,7 +132,13 @@ def _process_queue(self):

if event_type == "close":
if buffer_written:
self._flush(buffer)
try:
self._flush(buffer)
except Exception as exc:
logger.error(
"Exception occurred while flushing the buffer "
"before closing the transport connection: {0}".format(exc)
)
self._flushed.set()
return # time to go home!

Expand Down Expand Up @@ -257,7 +263,7 @@ def close(self):
self._closed = True
self.queue("close", None)
if not self._flushed.wait(timeout=self._max_flush_time):
raise ValueError("close timed out")
logger.error("Closing the transport connection timed out.")

stop_thread = close

Expand Down

0 comments on commit 9c79c89

Please sign in to comment.