Skip to content

fix(task_manager): reinitialize consumer threads after os.fork()#1654

Open
pyg410 wants to merge 3 commits into
langfuse:v2-stablefrom
pyg410:taskmanager-fork-safety
Open

fix(task_manager): reinitialize consumer threads after os.fork()#1654
pyg410 wants to merge 3 commits into
langfuse:v2-stablefrom
pyg410:taskmanager-fork-safety

style(task_manager): fix stdlib import order per PEP 8

ad72414
Select commit
Loading
Failed to load commit list.
Claude / Claude Code Review completed May 28, 2026 in 10m 29s

Code review found 2 potential issues

Found 5 candidates, confirmed 2. See review comments for details.

Details

Severity Count
🔴 Important 0
🟡 Nit 1
🟣 Pre-existing 0
Severity File:Line Issue
🟡 Nit langfuse/_task_manager/task_manager.py:93-97 At-fork callbacks accumulate per TaskManager (residual leak)

Annotations

Check warning on line 97 in langfuse/_task_manager/task_manager.py

See this annotation in the file changed.

@claude claude / Claude Code Review

At-fork callbacks accumulate per TaskManager (residual leak)

`os.register_at_fork` has no public unregister API in CPython, so each `TaskManager.__init__` permanently appends a fresh `lambda` (closing over a new `WeakMethod`) to the process-global at-fork list — and the entries are never reclaimed even after the `TaskManager` is GC'd. The `WeakMethod` correctly prevents the manager itself from being pinned, but the lambda+WeakMethod wrapper pair is not collectible, so in long-lived processes that build/tear down many Langfuse clients (e.g. pytest-xdist wi