Skip to content

Commit

Permalink
fix: various bugs in transport layer
Browse files Browse the repository at this point in the history
- if exception happens while calling task_done after a successful
request, task_done is (wrongly) called again
- all_tasks_done if unfinished_tasks transitions from 1 to 0. But the
queue might have been empty from the beginning, therefore this never
fires
  • Loading branch information
untitaker committed Aug 4, 2018
1 parent 246f699 commit 775557e
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions sentry_sdk/transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,11 @@ def thread():

try:
disabled_until = send_event(transport._pool, item, auth)
transport._queue.task_done()
except Exception:
print("Could not send sentry event", file=sys.stderr)
print(traceback.format_exc(), file=sys.stderr)
finally:
transport._queue.task_done()
continue

t = threading.Thread(target=thread)
t.setDaemon(True)
Expand Down Expand Up @@ -121,12 +120,10 @@ def close(self):

def drain_events(self, timeout):
q = self._queue
if q is None:
return True

with q.all_tasks_done:
q.all_tasks_done.wait(timeout)
return True
if q is not None:
with q.all_tasks_done:
while q.unfinished_tasks:
q.all_tasks_done.wait(timeout)

def __del__(self):
self.close()

0 comments on commit 775557e

Please sign in to comment.