Skip to content

fix: 🐛 ScopeFacade can be threadsafe#249

Merged
remimd merged 2 commits intodevfrom
threadsafe
May 24, 2025
Merged

fix: 🐛 ScopeFacade can be threadsafe#249
remimd merged 2 commits intodevfrom
threadsafe

Conversation

@remimd
Copy link
Copy Markdown
Member

@remimd remimd commented May 24, 2025

No description provided.

@remimd remimd requested a review from Copilot May 24, 2025 07:25
@remimd remimd self-assigned this May 24, 2025
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR makes ScopeFacade thread-safe by introducing a shared lock for binding and slot updates.

  • Pass a lock into _UserScope and use it to guard slot_map operations
  • Inline the binder context call and preserve locking for unbinding
Comments suppressed due to low confidence (2)

injection/_core/scope.py:327

  • [nitpick] The attribute name lock is generic and may collide with other variables; consider renaming to _scope_lock or similar to clarify its purpose and mark it as internal.
lock: ContextManager[Any]

injection/_core/scope.py:335

  • There are no tests covering concurrent calls to slot_map. Adding a test that runs slot_map from multiple threads would help ensure the new locking logic behaves correctly under contention.
with self.lock:

Comment thread injection/_core/scope.py
@remimd remimd merged commit 05c204d into dev May 24, 2025
5 checks passed
@remimd remimd deleted the threadsafe branch May 24, 2025 07:28
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