Skip to content

Commit 775557e

Browse files
committed
fix: various bugs in transport layer
- 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
1 parent 246f699 commit 775557e

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

sentry_sdk/transport.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,11 @@ def thread():
8080

8181
try:
8282
disabled_until = send_event(transport._pool, item, auth)
83-
transport._queue.task_done()
8483
except Exception:
8584
print("Could not send sentry event", file=sys.stderr)
8685
print(traceback.format_exc(), file=sys.stderr)
86+
finally:
8787
transport._queue.task_done()
88-
continue
8988

9089
t = threading.Thread(target=thread)
9190
t.setDaemon(True)
@@ -121,12 +120,10 @@ def close(self):
121120

122121
def drain_events(self, timeout):
123122
q = self._queue
124-
if q is None:
125-
return True
126-
127-
with q.all_tasks_done:
128-
q.all_tasks_done.wait(timeout)
129-
return True
123+
if q is not None:
124+
with q.all_tasks_done:
125+
while q.unfinished_tasks:
126+
q.all_tasks_done.wait(timeout)
130127

131128
def __del__(self):
132129
self.close()

0 commit comments

Comments
 (0)