{"record":{"id":"4e37f6ea11fde3ff","repo":"nautechsystems/nautilus_trader","slug":"stream-pool-events-database-error-e","errorCode":null,"errorMessage":"Stream pool events database error: {e}","messagePattern":"Stream pool events database error: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/blockchain/src/cache/database.rs","lineNumber":3270,"sourceCode":"                .bind(pos.transaction_index as i32)\n                .bind(pos.log_index as i32)\n                .bind(to_block.map(|block| block as i64))\n                .fetch(&self.pool)\n        } else {\n            sqlx::query(QUERY_ALL)\n                .bind(chain.chain_id as i32)\n                .bind(pool_identifier.to_string())\n                .bind(to_block.map(|block| block as i64))\n                .fetch(&self.pool)\n        };\n\n        // Transform rows to events\n        let stream = query.map(move |row_result| match row_result {\n            Ok(row) => {\n                transform_row_to_dex_pool_data(&row, chain.clone(), dex.clone(), instrument_id)\n                    .map_err(|e| anyhow::anyhow!(\"Steam pool event transform error: {e}\"))\n            }\n            Err(e) => Err(anyhow::anyhow!(\"Stream pool events database error: {e}\")),\n        });\n\n        Box::pin(stream)\n    }\n\n    /// Persists an execution transaction record to the `execution_transaction` table.\n    ///\n    /// Records are written before broadcast so a signed transaction is never forgotten;\n    /// the unique `(chain_id, transaction_hash)` constraint makes an exact re-insertion\n    /// idempotent. Signer nonce ownership and order IDs are unique before broadcast. Order\n    /// submission records carry the client order ID; operator transactions (wrap, approve)\n    /// store `NULL`.\n    ///\n    /// # Errors\n    ///\n    /// Returns an error if the database operation fails.\n    #[expect(\n        clippy::too_many_arguments,","sourceCodeStart":3252,"sourceCodeEnd":3288,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/blockchain/src/cache/database.rs#L3252-L3288","documentation":"This error wraps the sqlx row-level error when the database stream yields an Err for a row fetch while streaming pool events. The library surfaces it so the consumer of the stream knows the failure came from the database read itself, not the transform logic.","triggerScenarios":"Streaming pool events and the underlying connection drops mid-stream, a cursor/consumed-row error occurs, a statement timeout fires, or the connection is terminated by the server.","commonSituations":"Long-running streams over flaky networks; Postgres connection pool exhaustion or idle-connection timeout; server restarts during a live query.","solutions":["Inspect the inner `{e}` for the sqlx/sqlite/postgres error code","Increase connection pool size or idle/checkout timeouts if pool exhaustion is the cause","Add retry logic around stream consumption with resumable position (e.g. last log index)","Verify network stability and Postgres max_connections settings"],"exampleFix":"// before\nErr(e) => Err(anyhow::anyhow!(\"Stream pool events database error: {e}\")),\n// after\nErr(e) => {\n    tracing::error!(error = %e, \"pool events stream db error\");\n    Err(anyhow::anyhow!(\"Stream pool events database error: {e}\"))\n}","handlingStrategy":"retry","validationCode":"let healthy = sqlx::query(\"SELECT 1\").execute(&pool).await.is_ok();\nif !healthy { anyhow::bail!(\"database unavailable before streaming\"); }","typeGuard":null,"tryCatchPattern":"loop {\n    match stream_events(...).await {\n        Ok(stream) => { consume(stream).await; break; }\n        Err(e) if is_transient(&e) => { backoff().await; continue; }\n        Err(e) => return Err(e),\n    }\n}","preventionTips":["Size the connection pool for concurrent streams","Set sane statement/idle timeouts larger than stream duration","Resume streams from a persisted cursor (last log index) instead of restarting"],"tags":["database","sqlx","streaming"],"backgroundTag":"database-query-failed","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}