:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(error-tracking): route cymbal pg pools through common-database (#70527)
posthog[bot]46b0dbad45d1
diff --git a/rust/Cargo.lock b/rust/Cargo.lockindex 9423a0140034..1615cf0d3bc9 100644--- a/rust/Cargo.lock+++ b/rust/Cargo.lock@@ -2867,6 +2867,7 @@ dependencies = ["chrono","common-alloc","common-continuous-profiling",+ "common-database","common-dns","common-kafka","common-metrics",diff --git a/rust/cymbal/Cargo.toml b/rust/cymbal/Cargo.tomlindex b10bfd947bef..b68154acebf7 100644--- a/rust/cymbal/Cargo.toml+++ b/rust/cymbal/Cargo.toml@@ -17,6 +17,7 @@ common-metrics = { path = "../common/metrics" }common-alloc = { path = "../common/alloc" }common-continuous-profiling = { path = "../common/continuous_profiling" }common-kafka = { path = "../common/kafka" }+common-database = { path = "../common/database" }common-types = { path = "../common/types" }common-dns = { path = "../common/dns" }common-redis = { path = "../common/redis" }diff --git a/rust/cymbal/src/core/config.rs b/rust/cymbal/src/core/config.rsindex bf1f7950d11d..49f50b1a5dec 100644--- a/rust/cymbal/src/core/config.rs+++ b/rust/cymbal/src/core/config.rs@@ -1,5 +1,7 @@use aws_config::{BehaviorVersion, Region};+use common_database::{get_pool_with_config, PoolConfig};use envconfig::Envconfig;+use sqlx::PgPool;use tracing::{info, warn};/// Configuration for the shared symbol-resolution stack. Both run modes parse@@ -93,6 +95,26 @@ impl ResolverConfig {}}+/// Build the Postgres pool through the shared `common-database` helper so cymbal+/// gets `test_before_acquire` (severed connections are health-checked and+/// recycled instead of handed straight to a query), idle recycling, and the+/// disabled max-lifetime that avoids thundering-herd reconnects. Building the+/// pool directly with `PgPoolOptions` skips all of that, which is how a stale+/// connection turns into an `expected to read N bytes, got 0 bytes at EOF`+/// error mid-query. `pool_name` labels the connection-churn counter.+pub fn build_pg_pool(+ database_url: &str,+ max_connections: u32,+ pool_name: &str,+) -> Result<PgPool, sqlx::Error> {+ let pool_config = PoolConfig {+ max_connections,+ pool_name: Some(pool_name.to_string()),+ ..Default::default()+ };+ get_pool_with_config(database_url, pool_config)+}+pub async fn get_aws_config(config: &ResolverConfig) -> aws_sdk_s3::Config {// If we have a role ARN and token file, which are added to the container due to the SA annotation we use in prodif std::env::var("AWS_ROLE_ARN").is_ok() && std::env::var("AWS_WEB_IDENTITY_TOKEN_FILE").is_ok()diff --git a/rust/cymbal/src/core/resolver.rs b/rust/cymbal/src/core/resolver.rsindex 50b2ba92e9f5..c6e2605c1456 100644--- a/rust/cymbal/src/core/resolver.rs+++ b/rust/cymbal/src/core/resolver.rs@@ -1,9 +1,9 @@use std::sync::Arc;-use sqlx::{postgres::PgPoolOptions, PgPool};+use sqlx::PgPool;use tokio::sync::Mutex;-use crate::core::config::{get_aws_config, ResolverConfig};+use crate::core::config::{build_pg_pool, get_aws_config, ResolverConfig};use crate::core::error::UnhandledError;use crate::core::symbolication::symbol::{local::LocalSymbolResolver, SymbolResolver};use crate::core::symbolication::symbol_store::{@@ -31,8 +31,11 @@ use crate::core::symbolication::symbol_store::{pub async fn build_symbol_resolver(config: &ResolverConfig,) -> Result<Arc<dyn SymbolResolver>, UnhandledError> {- let options = PgPoolOptions::new().max_connections(config.max_pg_connections);- let posthog_pool = options.connect(&config.database_url).await?;+ let posthog_pool = build_pg_pool(+ &config.database_url,+ config.max_pg_connections,+ "cymbal_resolution",+ )?;let s3 = aws_sdk_s3::Client::from_conf(get_aws_config(config).await);let s3_client: Arc<dyn BlobClient> = Arc::new(S3Client::new(s3));s3_client.ping_bucket(&config.object_storage_bucket).await?;diff --git a/rust/cymbal/src/modes/notifications/context.rs b/rust/cymbal/src/modes/notifications/context.rsindex 345c3314c165..e77f551d08be 100644--- a/rust/cymbal/src/modes/notifications/context.rs+++ b/rust/cymbal/src/modes/notifications/context.rs@@ -3,8 +3,9 @@ use std::time::Duration;use common_kafka::kafka_producer::{create_kafka_producer, KafkaContext};use health::HealthRegistry;use rdkafka::producer::FutureProducer;-use sqlx::{postgres::PgPoolOptions, PgPool};+use sqlx::PgPool;+use crate::core::config::build_pg_pool;use crate::core::error::UnhandledError;use crate::modes::notifications::config::NotificationsConfig;use crate::modes::notifications::signals::{MaybeSignalClient, SignalClient};@@ -21,10 +22,11 @@ pub struct NotificationsContext {impl NotificationsContext {pub async fn from_config(config: &NotificationsConfig) -> Result<Self, UnhandledError> {- let posthog_pool = PgPoolOptions::new()- .max_connections(config.max_pg_connections)- .connect(&config.database_url)- .await?;+ let posthog_pool = build_pg_pool(+ &config.database_url,+ config.max_pg_connections,+ "cymbal_notifications",+ )?;let immediate_producer = build_immediate_producer(config).await?;Ok(Self {diff --git a/rust/cymbal/src/modes/processing/app_context.rs b/rust/cymbal/src/modes/processing/app_context.rsindex 18ce5467b362..cd2662ff205d 100644--- a/rust/cymbal/src/modes/processing/app_context.rs+++ b/rust/cymbal/src/modes/processing/app_context.rs@@ -3,14 +3,14 @@ use common_redis::{Client as RedisClientTrait, RedisClient};use health::HealthRegistry;use moka::future::{Cache, CacheBuilder};use rdkafka::producer::FutureProducer;-use sqlx::{postgres::PgPoolOptions, PgPool};+use sqlx::PgPool;use std::{collections::HashSet, sync::Arc, time::Duration};use tokio::{sync::Semaphore, task::JoinHandle};use tracing::info;use uuid::Uuid;use crate::{- core::config::get_aws_config,+ core::config::{build_pg_pool, get_aws_config},core::resolver::build_catalog,error::UnhandledError,modes::processing::config::{init_global_state, ProcessingConfig},@@ -73,8 +73,11 @@ impl Drop for AppContext {impl AppContext {pub async fn from_config(config: &ProcessingConfig) -> Result<Self, UnhandledError> {- let options = PgPoolOptions::new().max_connections(config.resolver.max_pg_connections);- let posthog_pool = options.connect(&config.resolver.database_url).await?;+ let posthog_pool = build_pg_pool(+ &config.resolver.database_url,+ config.resolver.max_pg_connections,+ "cymbal_processing",+ )?;let s3_client = aws_sdk_s3::Client::from_conf(get_aws_config(&config.resolver).await);let s3_client = S3Client::new(s3_client);