mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-07-31 19:16:29 +00:00
fix(gateway): close readiness-probe SQLite connection deterministically
Sibling of the #69678/#69567 ledger leak class found while widening the sweep: _probe_state_db used 'with sqlite3.connect(...)', whose context manager only commits/rolls back and never closes, leaking one connection (db fd) per health poll in the long-running gateway. Wrap the connection in contextlib.closing so every probe closes deterministically.
This commit is contained in:
parent
1d721a66f7
commit
81f60a0c84
1 changed files with 6 additions and 1 deletions
|
|
@ -4,6 +4,7 @@ from __future__ import annotations
|
|||
|
||||
import shutil
|
||||
import sqlite3
|
||||
from contextlib import closing
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
|
|
@ -31,8 +32,12 @@ def _probe_state_db(home: Path) -> dict[str, Any]:
|
|||
# A readiness probe must never compete with normal state writers. A
|
||||
# read-only schema query still catches unreadable/corrupt databases
|
||||
# without taking a write reservation on every health poll.
|
||||
# ``closing(...)`` is required: sqlite3's connection context manager
|
||||
# only commits/rolls back — it never closes, so a bare ``with
|
||||
# sqlite3.connect(...)`` leaks one connection (and its fds) per
|
||||
# health poll in the long-running gateway (#69678/#69567 bug class).
|
||||
uri = f"file:{path.as_posix()}?mode=ro"
|
||||
with sqlite3.connect(uri, uri=True, timeout=1.0) as conn:
|
||||
with closing(sqlite3.connect(uri, uri=True, timeout=1.0)) as conn:
|
||||
conn.execute("PRAGMA query_only = ON")
|
||||
conn.execute("SELECT name FROM sqlite_master LIMIT 1").fetchone()
|
||||
return _check("ok")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue