Skip to content

Commit dc1d501

Browse files
committed
Add reset of the running flag
1 parent 17b3e0a commit dc1d501

5 files changed

Lines changed: 16 additions & 4 deletions

File tree

sentry_sdk/_batcher.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ def _reset_in_child() -> None:
5252

5353
def _reset_thread_state(self) -> None:
5454
self._buffer = []
55+
self._running = True
5556
self._lock = threading.Lock()
5657
self._active = threading.local()
5758
self._flush_event = threading.Event()

sentry_sdk/_span_batcher.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ def _reset_in_child() -> None:
6666
def _reset_thread_state(self) -> None:
6767
self._span_buffer = defaultdict(list)
6868
self._running_size = defaultdict(lambda: 0)
69+
self._running = True
6970

7071
self._lock = threading.Lock()
7172
self._active = threading.local()

tests/test_logs.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -844,21 +844,24 @@ def test_log_batcher_lock_reset_in_child_after_fork(sentry_init):
844844

845845
original_lock = batcher._lock
846846
original_lock.acquire()
847+
847848
batcher._buffer.append(object())
848849
batcher._active.flag = True
849850
batcher._flush_event.set()
851+
batcher._running = False
852+
850853
pid = os.fork()
851854
if pid == 0:
852-
# Child: was the lock object replaced and is the new one not
853-
# held? Without the fix, _lock is `original_lock` inherited
854-
# locked, so `replaced` is False. blocking=False guarantees the
855-
# child can't hang on a regression.
856855
replaced = batcher._lock is not original_lock
857856
unheld = batcher._lock.acquire(blocking=False)
857+
858858
flusher_reset = batcher._flusher is None and batcher._flusher_pid is None
859859
buffer_reset = len(batcher._buffer) == 0
860860
active_reset = not getattr(batcher._active, "flag", False)
861+
861862
event_reset = not batcher._flush_event.is_set()
863+
running_reset = batcher._running is True
864+
862865
os._exit(
863866
0
864867
if replaced
@@ -867,6 +870,7 @@ def test_log_batcher_lock_reset_in_child_after_fork(sentry_init):
867870
and buffer_reset
868871
and active_reset
869872
and event_reset
873+
and running_reset
870874
else 1
871875
)
872876

tests/test_metrics.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,7 @@ def test_metrics_batcher_lock_reset_in_child_after_fork(sentry_init):
543543
batcher._buffer.append(object())
544544
batcher._active.flag = True
545545
batcher._flush_event.set()
546+
batcher._running = False
546547

547548
pid = os.fork()
548549
if pid == 0:
@@ -553,6 +554,7 @@ def test_metrics_batcher_lock_reset_in_child_after_fork(sentry_init):
553554
buffer_reset = len(batcher._buffer) == 0
554555
active_reset = not getattr(batcher._active, "flag", False)
555556
event_reset = not batcher._flush_event.is_set()
557+
running_reset = batcher._running is True
556558

557559
os._exit(
558560
0
@@ -562,6 +564,7 @@ def test_metrics_batcher_lock_reset_in_child_after_fork(sentry_init):
562564
and buffer_reset
563565
and active_reset
564566
and event_reset
567+
and running_reset
565568
else 1
566569
)
567570

tests/tracing/test_span_streaming.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1588,6 +1588,7 @@ def test_span_batcher_lock_reset_in_child_after_fork(sentry_init):
15881588
batcher._running_size["test-trace-id"] = 42
15891589
batcher._active.flag = True
15901590
batcher._flush_event.set()
1591+
batcher._running = False
15911592

15921593
pid = os.fork()
15931594
if pid == 0:
@@ -1600,6 +1601,7 @@ def test_span_batcher_lock_reset_in_child_after_fork(sentry_init):
16001601

16011602
active_reset = not getattr(batcher._active, "flag", False)
16021603
event_reset = not batcher._flush_event.is_set()
1604+
running_reset = batcher._running is True
16031605

16041606
os._exit(
16051607
0
@@ -1610,6 +1612,7 @@ def test_span_batcher_lock_reset_in_child_after_fork(sentry_init):
16101612
and running_size_reset
16111613
and active_reset
16121614
and event_reset
1615+
and running_reset
16131616
else 1
16141617
)
16151618

0 commit comments

Comments
 (0)