Skip to content

Incorrect use of threading. Lock in Async Methods (MemoryStorage, TranscriptMemoryStore) #190

@cleemullins

Description

@cleemullins

Use of threading. Lock in Async Methods (MemoryStorage, TranscriptMemoryStore)

Files: memory_storage.py, transcript_memory_store.py

Pattern: performing trivial dict/list operations inside with self._lock: in async def. Currently safe because no awaits inside critical sections. However:

  • If future changes add awaits inside the with blocks, deadlocks/blocking risk arises (like Cosmos issue).
  • In an asyncio-only deployment (single thread), threading.Lock is unnecessary; an asyncio.Lock would be more semantically correct.
  • In free-threaded Python (3.13t/3.14t) scenarios, using a standard Lock may still be fine, but code clarity improves with explicit async primitives.
  • Recommendation: Migrate to asyncio.Lock unless true multi-thread writers are expected. Document invariants.

Metadata

Metadata

Assignees

Labels

BugSomething isn't workingP1

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions