fix(postgres): reset search_path after schema-scoped queries to prevent pool connection state leak

SET search_path in PostgreSQL is not transactional — it survives rollback
and persists on the connection. Previously, connections returned to the pool
with a modified search_path, causing subsequent queries on the same
connection to run against the wrong schema. Now RESET search_path is always
called after schema-scoped queries and transactions.
This commit is contained in:
t8y2 committed 2026-05-24 19:22:55 +08:00
1 parent 7b9a04ff3e
commit a34a8abe65
2 files changed
+37 -9

No files matched your search

+13
View File
@@ -463,6 +463,19 @@ pub async fn execute_query_with_schema_and_max_rows(
.await
.map_err(|e| e.to_string())?;
let result = execute_query_with_max_rows_inner(&client, sql, max_rows).await;
// Always reset search_path so the connection is clean when returned to the pool
let _ = client.execute("RESET search_path", &[]).await;
result
}
async fn execute_query_with_max_rows_inner(
client: &deadpool_postgres::Client,
sql: &str,
max_rows: Option<usize>,
) -> Result<QueryResult, String> {
let start = Instant::now();
let row_limit = query_result_row_limit(max_rows);