Skip to content

bug(storage): SQLiteManager.close() lacks lock, races with concurrent operations #6619

Description

@bennyyuan1008

Bug Description

SQLiteManager.close() is the only public method on the class that does not acquire self._lock before touching self.connection. Under concurrency, a close() call from one thread while another is mid-transaction (e.g., in add_history) can:

  1. Read self.connection as valid, close it, set it to None
  2. The other thread then calls self.connection.execute("COMMIT") on None, crashing with AttributeError
  3. The except handler in the other thread also tries ROLLBACK on None, masking the original error

The same risk applies via del which calls close() without the lock.

Fix

Add with self._lock: to close().

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions