Commit cf0eca5
committed
fix: Replace per-call Lock creation with shared lock in SQLiteSession
The lock pattern 'with self._lock if self._is_memory_db else threading.Lock()'
creates a new Lock object for each operation when using file-based databases,
providing no thread safety for concurrent access.
This fix uses the shared self._lock for both memory and file databases,
ensuring proper synchronization for concurrent operations.
Changes:
- get_items() (line 123)
- add_items() (line 177)
- pop_item() (line 218)
- clear_session() (line 255)
Testing:
- Existing test test_sqlite_session_concurrent_access passes
- Manual verification shows proper lock reuse
- No breaking changes to API or behavior1 parent d1abf43 commit cf0eca5
1 file changed
+9
-4
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
| |||
55 | 56 | | |
56 | 57 | | |
57 | 58 | | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
58 | 63 | | |
59 | 64 | | |
60 | 65 | | |
| |||
120 | 125 | | |
121 | 126 | | |
122 | 127 | | |
123 | | - | |
| 128 | + | |
124 | 129 | | |
125 | 130 | | |
126 | 131 | | |
| |||
174 | 179 | | |
175 | 180 | | |
176 | 181 | | |
177 | | - | |
| 182 | + | |
178 | 183 | | |
179 | 184 | | |
180 | 185 | | |
| |||
215 | 220 | | |
216 | 221 | | |
217 | 222 | | |
218 | | - | |
| 223 | + | |
219 | 224 | | |
220 | 225 | | |
221 | 226 | | |
| |||
252 | 257 | | |
253 | 258 | | |
254 | 259 | | |
255 | | - | |
| 260 | + | |
256 | 261 | | |
257 | 262 | | |
258 | 263 | | |
| |||
0 commit comments