Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-seed random ID generator after os.fork() #644

Merged
merged 1 commit into from
Dec 5, 2024
Merged

Conversation

alexmojaki
Copy link
Contributor

os.fork() copied the SeededRandomIdGenerator state so that the parent and child processes would generate the same pseudorandom trace/span IDs, which is very bad. Demo script that this PR fixes:

import os
import logfire

logfire.configure()

logfire.info('log', pids=(os.fork(), os.getpid()))

@alexmojaki alexmojaki enabled auto-merge (squash) December 5, 2024 15:07
@alexmojaki alexmojaki merged commit 15cc6fb into main Dec 5, 2024
12 checks passed
@alexmojaki alexmojaki deleted the alex/fork-seed branch December 5, 2024 15:11
Copy link

codecov bot commented Dec 5, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (e793014) to head (73806bc).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #644   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          135       135           
  Lines        10681     10683    +2     
  Branches      1465      1466    +1     
=========================================
+ Hits         10681     10683    +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@phil65
Copy link

phil65 commented Dec 5, 2024

Just fyi, this broke logfire for me (using windows):

File "E:\llmling.venv\Lib\site-packages\logfire_internal\utils.py", line 378, in post_init
os.register_at_fork(after_in_child=self.random.seed)
^^^^^^^^^^^^^^^^^^^
AttributeError: module 'os' has no attribute 'register_at_fork'

@alexmojaki
Copy link
Contributor Author

Thanks @phil65 for reporting, released another fix: https://github.com/pydantic/logfire/releases/tag/v2.6.2

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.

2 participants