Skip to content

Commit 1ee719a

Browse files
authored
fix: resolve SQLite 'database is locked' errors under high concurrency (#5558)
1 parent 70b8884 commit 1ee719a

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/_bentoml_impl/tasks/result.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ def _connect(self, db_file: str) -> Connection:
111111

112112
async def __aenter__(self) -> "t.Self":
113113
self._conn = await self._conn
114-
await self._conn.execute("PRAGMA journal_mode=WAL")
115114
await self._conn.execute("PRAGMA busy_timeout=5000")
116115
return self
117116

@@ -127,6 +126,8 @@ def init_db(cls, db_file: str) -> None:
127126
detect_types=sqlite3.PARSE_DECLTYPES | sqlite3.PARSE_COLNAMES,
128127
timeout=30.0,
129128
) as conn:
129+
conn.execute("PRAGMA journal_mode=WAL")
130+
conn.execute("PRAGMA busy_timeout=5000")
130131
conn.execute(
131132
textwrap.dedent("""\
132133
CREATE TABLE IF NOT EXISTS result (
@@ -199,7 +200,7 @@ async def get_status(self, task_id: str) -> ResultRow:
199200

200201
async def set_status(self, task_id: str, status: ResultStatus) -> None:
201202
await self._conn.execute(
202-
"UPDATE result SET status = ?, updated_at = ? WHERE task_id = ? AND status = ?",
203+
"UPDATE result SET status = ?, executed_at = ? WHERE task_id = ? AND status = ?",
203204
(
204205
status.value,
205206
datetime.datetime.now(tz=datetime.timezone.utc),

0 commit comments

Comments
 (0)