{"record":{"id":"da87f634c57f9523","repo":"nautechsystems/nautilus_trader","slug":"failed-to-lock-recoverable-execution-intent-e","errorCode":null,"errorMessage":"Failed to lock recoverable execution intent: {e}","messagePattern":"Failed to lock recoverable execution intent: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/blockchain/src/cache/database.rs","lineNumber":6520,"sourceCode":"        Ok(())\n    }\n\n    /// Releases an intent when no broadcast attempt can have occurred.\n    ///\n    /// # Errors\n    ///\n    /// Returns an error if the intent advanced to broadcast or persistence fails.\n    pub async fn mark_execution_intent_recoverable(&self, intent_id: i64) -> anyhow::Result<()> {\n        let mut transaction = self.pool.begin().await.map_err(|e| {\n            anyhow::anyhow!(\"Failed to start recoverable execution transition: {e}\")\n        })?;\n        let current_status = sqlx::query_scalar::<_, String>(\n            \"SELECT status FROM execution_intent WHERE id = $1 FOR UPDATE\",\n        )\n        .bind(intent_id)\n        .fetch_optional(&mut *transaction)\n        .await\n        .map_err(|e| anyhow::anyhow!(\"Failed to lock recoverable execution intent: {e}\"))?\n        .ok_or_else(|| anyhow::anyhow!(\"Execution intent {intent_id} was not found\"))?;\n        anyhow::ensure!(\n            current_status == \"prepared\",\n            \"Execution intent {intent_id} is {current_status}, not recoverable before signing\"\n        );\n        let result = sqlx::query(\n            \"\n            UPDATE execution_intent\n            SET status = 'recoverable', active = FALSE, updated_at = NOW()\n            WHERE id = $1 AND status = 'prepared'\n            \",\n        )\n        .bind(intent_id)\n        .execute(&mut *transaction)\n        .await\n        .map_err(|e| anyhow::anyhow!(\"Failed to mark execution intent recoverable: {e}\"))?;\n        anyhow::ensure!(\n            result.rows_affected() == 1,","sourceCodeStart":6502,"sourceCodeEnd":6538,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/blockchain/src/cache/database.rs#L6502-L6538","documentation":"Immediately after starting the transaction, the function runs `SELECT status FROM execution_intent WHERE id = $1 FOR UPDATE` to lock the intent row. If that query fails at the database level (connection drop, lock timeout, server error), the sqlx error is wrapped as this message. A missing row is reported separately as 'Execution intent {id} was not found'.","triggerScenarios":"Calling `mark_execution_intent_recoverable` while the connection dies mid-query, the row lock cannot be acquired within the server's lock_timeout, or the PostgreSQL server returns an error during the `FOR UPDATE` select.","commonSituations":"Another long transaction holds the `execution_intent` row lock past `lock_timeout`; the network drops between `begin()` and the select; a failover terminates the session after the transaction started.","solutions":["Retry the call after the transient condition clears — the transaction rolled back so no partial state persists.","Check for competing transactions holding `FOR UPDATE` locks on `execution_intent` and shorten them.","Raise or remove a restrictive `lock_timeout` on the session/database if legitimate contention is expected.","Verify connection stability (keepalives, pool health) between the app and PostgreSQL."],"exampleFix":"// before: single attempt, hard failure\nif let Err(e) = db.mark_execution_intent_recoverable(intent_id).await { return Err(e); }\n// after: retry on lock-related failures\nmatch db.mark_execution_intent_recoverable(intent_id).await {\n    Ok(()) => {},\n    Err(e) if e.to_string().contains(\"lock\") => {\n        tokio::time::sleep(Duration::from_secs(1)).await;\n        db.mark_execution_intent_recoverable(intent_id).await?;\n    }\n    Err(e) => return Err(e),\n}","handlingStrategy":"retry","validationCode":"let exists = sqlx::query_scalar::<_, String>(\"SELECT status FROM execution_intent WHERE id=$1\").bind(intent_id).fetch_optional(&pool).await?;\nif exists.is_none() { return Err(anyhow!(\"intent {intent_id} does not exist\")); }","typeGuard":null,"tryCatchPattern":"match db.mark_execution_intent_recoverable(id).await {\n    Err(e) if e.to_string().contains(\"Failed to lock recoverable execution intent\") => { tokio::time::sleep(Duration::from_millis(500)).await; db.mark_execution_intent_recoverable(id).await?; }\n    Err(e) => return Err(e),\n    Ok(()) => {},\n}","preventionTips":["Keep transactions touching `execution_intent` short to avoid prolonged `FOR UPDATE` lock holds.","Set an explicit lock_timeout and retry on lock-wait errors instead of failing hard.","Avoid running recoverability sweeps concurrently with long-lived intent transactions.","Enable TCP keepalives so dropped connections surface quickly and roll back cleanly."],"tags":["database","locking","transient"],"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-23T08:17:48.524Z"}