Skip to content

fix(storage): add missing lock to SQLiteManager.close() - #6620

Open
bennyyuan1008 wants to merge 1 commit into
mem0ai:mainfrom
bennyyuan1008:fix/sqlite-close-lock
Open

fix(storage): add missing lock to SQLiteManager.close()#6620
bennyyuan1008 wants to merge 1 commit into
mem0ai:mainfrom
bennyyuan1008:fix/sqlite-close-lock

Conversation

@bennyyuan1008

Copy link
Copy Markdown

Linked Issue

Closes #6619

Description

SQLiteManager.close() was the only public method that did not acquire self._lock before touching self.connection. Under concurrency, a concurrent close() while another thread is mid-transaction can crash with AttributeError on NoneType connection, and the cascading ROLLBACK failure masks the original error.

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

Fix: Add with self._lock: to close().

Type of Change

  • Bug fix

Test Coverage

  • All 15 tests in tests/memory/test_storage.py pass
  • Ruff clean

Checklist

  • My code follows the project style guidelines
  • I have performed a self-review of my code
  • New and existing tests pass locally

@github-actions github-actions Bot added the sdk-python Python SDK specific label Jul 27, 2026
close() was the only public method on SQLiteManager that did not acquire self._lock before touching self.connection. Under concurrency, a close() call from one thread while another was mid-transaction could cause AttributeError on NoneType connection, and the cascading ROLLBACK failure would mask the original error.

The same risk existed from __del__ which also called close() without the lock.

Fixed by wrapping the body in with self._lock.
@bennyyuan1008
bennyyuan1008 force-pushed the fix/sqlite-close-lock branch from 715b175 to 79c9104 Compare July 27, 2026 05:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

sdk-python Python SDK specific

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant