Skip to content

🐛 Make GlobalThreadPool initialization thread-safe - #3824

Open
original4422 wants to merge 1 commit into
ModelEngine-Group:developfrom
original4422:fix/thread-pool-singleton-3820
Open

🐛 Make GlobalThreadPool initialization thread-safe#3824
original4422 wants to merge 1 commit into
ModelEngine-Group:developfrom
original4422:fix/thread-pool-singleton-3820

Conversation

@original4422

Copy link
Copy Markdown

Summary

  • synchronize lazy singleton construction and publish the pool only after its executor is ready
  • retain the module-level five-worker pool and warn when a later caller requests a different worker count
  • add deterministic CPU-only regression coverage for construction races, conflicting worker counts, and submit delegation

Root cause

GlobalThreadPool.__new__ published _instance before ThreadPoolExecutor construction completed, so another thread could receive an incompletely initialized singleton. It also silently retained the first worker count on later conflicting calls.

Testing

  • uv run --with pytest pytest test/backend/utils/test_thread_utils.py -q (3 passed)
  • uv run --with ruff ruff check backend/utils/thread_utils.py test/backend/utils/test_thread_utils.py
  • git diff --check

Fixes #3820

@original4422
original4422 requested a review from WMC001 as a code owner August 31, 2026 07:18
Copilot AI lite review requested due to automatic review settings August 31, 2026 07:18

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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.

GlobalThreadPool singleton: unsynchronised __new__ and silently ignored max_workers

2 participants