@@ -1570,7 +1570,9 @@ def test_span_batcher_lock_reset_in_child_after_fork(sentry_init):
15701570 child inherits the lock locked. The holding thread does not exist in
15711571 the child, so the lock can never be released and _ensure_thread
15721572 deadlocks forever. The after-fork hook must replace the lock with a
1573- fresh one in the child and reset _flusher / _flusher_pid.
1573+ fresh one in the child and reset
1574+ _flusher / _flusher_pid / _span_buffer / _running_size / _active /
1575+ _flush_event.
15741576 """
15751577 sentry_init (
15761578 traces_sample_rate = 1.0 ,
@@ -1581,16 +1583,35 @@ def test_span_batcher_lock_reset_in_child_after_fork(sentry_init):
15811583
15821584 original_lock = batcher ._lock
15831585 original_lock .acquire ()
1586+
1587+ batcher ._span_buffer ["test-trace-id" ].append (object ())
1588+ batcher ._running_size ["test-trace-id" ] = 42
1589+ batcher ._active .flag = True
1590+ batcher ._flush_event .set ()
1591+
15841592 pid = os .fork ()
15851593 if pid == 0 :
1586- # Child: was the lock object replaced and is the new one not
1587- # held? Without the fix, _lock is `original_lock` inherited
1588- # locked, so `replaced` is False. blocking=False guarantees the
1589- # child can't hang on a regression.
15901594 replaced = batcher ._lock is not original_lock
15911595 unheld = batcher ._lock .acquire (blocking = False )
1596+
15921597 flusher_reset = batcher ._flusher is None and batcher ._flusher_pid is None
1593- os ._exit (0 if replaced and unheld and flusher_reset else 1 )
1598+ span_buffer_reset = len (batcher ._span_buffer ) == 0
1599+ running_size_reset = len (batcher ._running_size ) == 0
1600+
1601+ active_reset = not getattr (batcher ._active , "flag" , False )
1602+ event_reset = not batcher ._flush_event .is_set ()
1603+
1604+ os ._exit (
1605+ 0
1606+ if replaced
1607+ and unheld
1608+ and flusher_reset
1609+ and span_buffer_reset
1610+ and running_size_reset
1611+ and active_reset
1612+ and event_reset
1613+ else 1
1614+ )
15941615
15951616 original_lock .release ()
15961617 _ , status = os .waitpid (pid , 0 )
0 commit comments