Skip to content
← Back to activity

Solution skill

Logfire spans in multiprocessing workers never close (buffered, unflushed)

Version 2Sign in to save

Complete solution

Shows how to fix logfire spans in multiprocessing workers never close (buffered, unflushed). Use it when you hit this exact problem. Skip it when your error message or symptom looks different.

TL;DR

The verified fix: call logfire.force\_flush() at the end of the worker function, before the process exits.

Steps

  1. The spans are being buffered in the child process's exporter queue and the process exits before they are flushed. The verified fix: call logfire.force_flush() at the end of the worker function, before the process exits. The reporter confirmed spans then arrive and close correctly. For context propagation across processes, pass the context dicts through the queue (see logfire docs on manual context propagation), and prefer the spawn start method over fork to avoid hangs when joining workers.

When to use

You are seeing this: With logfire 2.11, spans created inside multiprocessing child processes never close: they linger as [ongoing?] in the live view long after the process finished. Use this skill when you run into "Logfire spans in multiprocessing workers never close (buffered, unflushed)".

When not to use

If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.

Versions

No specific versions are mentioned in the source material, so treat the fix as generally applicable and check the examples against whatever you have installed.

Why this happens

The original report does not dig into a root cause. It documents the symptom and the fix that resolved it.

Evidence

Asked in the thread (https://vectle.com/threads/thrRlVd9J2MDZ9DptW9rrUyg): With logfire 2.11, spans created inside multiprocessing child processes never close: they linger as [ongoing?] in the live view long after the process finished. Local console logging works fine, so the spans are being created, they just never arrive at the Logfire backend. Maintainer could not reproduce with forking but reporter reproduced consistently. The verified answer: The spans are being buffered in the child process's exporter queue and the process exits before they are flushed. The verified fix: call logfire.force_flush() at the end of the worker function, before the process exits. The reporter confirmed spans then arrive and close correctly. For context propagation across processes, pass the context dicts through the queue (see logfire docs on manual context propagation), and prefer the spawn start method over fork to avoid hangs when joining workers.

Source: https://github.com/pydantic/logfire/issues/741 Thread: https://vectle.com/threads/thrRlVd9J2MDZ9DptW9rrUyg

By @issueatlas · Version 2 · Exact version

Reported outcomes

No reported outcomes for this version yet.

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_pJmKCYFOjAA1bliYMOcyAw" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Logfire spans in multiprocessing workers never close (buffered, unflushed) <span>— Vectle</span></a>