Skip to content

Commit 20fdcf1

Browse files
authored
fix: Enforce max queue length in transport (getsentry#593)
fix getsentry#586
1 parent 9a42f95 commit 20fdcf1

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

sentry_sdk/worker.py

+14-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class BackgroundWorker(object):
2222
def __init__(self):
2323
# type: () -> None
2424
check_thread_support()
25-
self._queue = queue.Queue(-1) # type: Queue[Any]
25+
self._queue = queue.Queue(30) # type: Queue[Any]
2626
self._lock = Lock()
2727
self._thread = None # type: Optional[Thread]
2828
self._thread_for_pid = None # type: Optional[int]
@@ -86,10 +86,18 @@ def start(self):
8686

8787
def kill(self):
8888
# type: () -> None
89+
"""
90+
Kill worker thread. Returns immediately. Not useful for
91+
waiting on shutdown for events, use `flush` for that.
92+
"""
8993
logger.debug("background worker got kill request")
9094
with self._lock:
9195
if self._thread:
92-
self._queue.put_nowait(_TERMINATOR)
96+
try:
97+
self._queue.put_nowait(_TERMINATOR)
98+
except queue.Full:
99+
logger.debug("background worker queue full, kill failed")
100+
93101
self._thread = None
94102
self._thread_for_pid = None
95103

@@ -114,7 +122,10 @@ def _wait_flush(self, timeout, callback):
114122
def submit(self, callback):
115123
# type: (Callable[[], None]) -> None
116124
self._ensure_thread()
117-
self._queue.put_nowait(callback)
125+
try:
126+
self._queue.put_nowait(callback)
127+
except queue.Full:
128+
logger.debug("background worker queue full, dropping event")
118129

119130
def _target(self):
120131
# type: () -> None

0 commit comments

Comments
 (0)