Skip to content

Conversation

@gregoiredx
Copy link

@gregoiredx gregoiredx commented Dec 17, 2025

Description

ConcurrentMultiSpanProcessor is not "fork safe". This MR tries to solve this problem.

Forking a threaded process is not a good idea in the first place, citing the Python doc, see https://docs.python.org/3/library/multiprocessing.html#contexts-and-start-methods

Note that safely forking a multithreaded process is problematic.

Also, the OTel Python SDK suggest to only initialize the SDK post fork, see https://opentelemetry-python.readthedocs.io/en/latest/examples/fork-process-model/README.html

Nevertheless, on an existing code base, it's not always easy to avoid all forks. So it looks like a good idea to try and make the SDK as fork safe as possible.

Note: BatchProcessor is already relying on register_at_fork used here, see

os.register_at_fork(after_in_child=lambda: weak_reinit()()) # pyright: ignore[reportOptionalCall] pylint: disable=unnecessary-lambda

Fixes #2349

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

It's quite hard to unit test.

An equivalent patch is currently running in our stack.

Does This PR Require a Contrib Repo Change?

?

Checklist:

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Dec 17, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: gregoiredx / name: Grégoire Deveaux (f98d672)

@gregoiredx gregoiredx force-pushed the fork-safe-concurrent-multi-span-processor branch from 3abcc2e to f98d672 Compare December 17, 2025 13:48
@gregoiredx gregoiredx marked this pull request as ready for review December 22, 2025 08:50
@gregoiredx gregoiredx requested a review from a team as a code owner December 22, 2025 08:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ConcurrentMultiSpanProcessor threadpool should be reset after process forked

1 participant