Skip to content

Commit

Permalink
Catch and log any exceptions while closing the transport (#838)
Browse files Browse the repository at this point in the history
* Catch and log any exceptions while closing the transport

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 #823

* Remove trailing comma

I don't know how this happened, I think black added it? But then it
didn't re-add it this time when I removed it. Probably more of
black's magic comma stuff that has been added recently

* Add to changelog
  • Loading branch information
basepi committed Jun 5, 2020
1 parent c9c290c commit 321a344
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.asciidoc
Expand Up @@ -35,6 +35,7 @@ endif::[]
* Limit SQL queries in context data to 10000 characters {pull}842[#842]
* Omit the "sync" property on spans by default {pull}854[#854]
* Update the pid/ppid in transport metadata when they change {pull}825[#825]
* Added better error handling around closing the transport {pull}838[#838]
[[release-notes-5.x]]
=== Python Agent version 5.x
Expand Down
10 changes: 8 additions & 2 deletions elasticapm/transport/base.py
Expand Up @@ -130,7 +130,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 @@ -258,7 +264,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 321a344

Please sign in to comment.