mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-09-09 00:04:10 +00:00
fix: prevent idle queries at the sqlx level
This commit is contained in:
@@ -339,7 +339,7 @@ pub async fn connect(
|
||||
worker_mode: bool,
|
||||
) -> Result<sqlx::Pool<sqlx::Postgres>, error::Error> {
|
||||
use std::time::Duration;
|
||||
|
||||
use sqlx::Executor;
|
||||
sqlx::postgres::PgPoolOptions::new()
|
||||
.min_connections((max_connections / 5).clamp(3, max_connections))
|
||||
.max_connections(max_connections)
|
||||
@@ -347,13 +347,30 @@ pub async fn connect(
|
||||
.after_connect(move |conn, _| {
|
||||
if worker_mode {
|
||||
Box::pin(async move {
|
||||
sqlx::query("SET enable_seqscan = OFF;")
|
||||
.execute(conn)
|
||||
.await?;
|
||||
if let Err(e) = conn.execute(r#"
|
||||
SET enable_seqscan = OFF;
|
||||
SET statement_timeout = '5min';
|
||||
SET idle_in_transaction_session_timeout = '10min';
|
||||
SET tcp_keepalives_idle = 300;
|
||||
SET tcp_keepalives_interval = 60;
|
||||
SET tcp_keepalives_count = 10;"#)
|
||||
.await {
|
||||
tracing::error!("Error setting postgres settings: {}", e);
|
||||
}
|
||||
Ok(())
|
||||
})
|
||||
} else {
|
||||
Box::pin(async move { Ok(()) })
|
||||
Box::pin(async move {
|
||||
if let Err(e) = conn.execute(r#"
|
||||
SET statement_timeout = '5min';
|
||||
SET idle_in_transaction_session_timeout = '10min';
|
||||
SET tcp_keepalives_idle = 300;
|
||||
SET tcp_keepalives_interval = 60;
|
||||
SET tcp_keepalives_count = 10;"#)
|
||||
.await {
|
||||
tracing::error!("Error setting postgres settings: {}", e);
|
||||
}
|
||||
Ok(()) })
|
||||
}
|
||||
})
|
||||
.connect_with(
|
||||
|
||||
Reference in New Issue
Block a user