Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion crates/cli/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use mas_storage::RepositoryAccess;
use mas_storage_pg::PgRepository;
use mas_templates::{SiteConfigExt, TemplateLoadingError, Templates};
use sqlx::{
ConnectOptions, PgConnection, PgPool,
ConnectOptions, Executor, PgConnection, PgPool,
postgres::{PgConnectOptions, PgPoolOptions},
};
use tokio_util::{sync::CancellationToken, task::TaskTracker};
Expand Down Expand Up @@ -339,6 +339,15 @@ pub async fn database_pool_from_config(config: &DatabaseConfig) -> Result<PgPool
.acquire_timeout(config.connect_timeout)
.idle_timeout(config.idle_timeout)
.max_lifetime(config.max_lifetime)
.after_connect(|conn, _meta| {
Box::pin(async move {
// Unlisten from all channels, as we might be connected via a connection pooler
// that doesn't clean up LISTEN/NOTIFY state when reusing connections.
conn.execute("UNLISTEN *;").await?;

Ok(())
})
})
.connect_with(options)
.await
.context("could not connect to the database")
Expand Down
Loading