{"record":{"id":"4d4db30d584d2d2f","repo":"nautechsystems/nautilus_trader","slug":"failed-to-send-delete-position-command-e","errorCode":null,"errorMessage":"Failed to send delete position command: {e}","messagePattern":"Failed to send delete position command: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/infrastructure/src/redis/cache.rs","lineNumber":605,"sourceCode":"        }\n\n        Ok(())\n    }\n\n    /// Delete the given position from the database with full index cleanup.\n    ///\n    /// # Errors\n    ///\n    /// Returns an error if the command cannot be sent to the background task channel.\n    pub fn delete_position(&self, position_id: &PositionId) -> anyhow::Result<()> {\n        let position_id_bytes = Bytes::from(position_id.to_string());\n\n        // Delete the position itself\n        let key = format!(\"{POSITIONS}{REDIS_DELIMITER}{position_id}\");\n        let op = DatabaseCommand::new(DatabaseOperation::Delete, key, None);\n        self.tx\n            .send(op)\n            .map_err(|e| anyhow::anyhow!(\"Failed to send delete position command: {e}\"))?;\n\n        // Delete from all position indexes\n        let index_keys = [\n            INDEX_POSITIONS,\n            INDEX_POSITIONS_OPEN,\n            INDEX_POSITIONS_CLOSED,\n        ];\n\n        for index_key in &index_keys {\n            let key = (*index_key).to_string();\n            let payload = vec![position_id_bytes.clone()];\n            let op = DatabaseCommand::new(DatabaseOperation::Delete, key, Some(payload));\n            self.tx.send(op).map_err(|e| {\n                anyhow::anyhow!(\"Failed to send delete position index command: {e}\")\n            })?;\n        }\n\n        Ok(())","sourceCodeStart":587,"sourceCodeEnd":623,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/infrastructure/src/redis/cache.rs#L587-L623","documentation":"delete_position queues a Delete command for the position record itself via the internal command channel. This error means the send failed because the Redis writer task no longer holds a live receiver.","triggerScenarios":"Calling delete_position (or py_delete_position) after the background command-processing task has been dropped or shut down.","commonSituations":"Position cleanup during node shutdown, after a Redis outage terminated the writer task, or on a cache adapter whose command loop never ran.","solutions":["Verify the cache database task is running and reconnect if it was stopped.","Avoid calling delete_position after node shutdown has begun.","Find and fix the earlier failure (connection loss, panic) that ended the writer task.","Restart the trading node or rebuild the RedisCache adapter and re-attempt the delete."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"match cache.delete_position(&position_id) {\n    Err(e) if e.to_string().contains(\"Failed to send delete position command\") => {\n        // writer task unavailable: reconnect or defer until restart\n    }\n    result => result?,\n}","preventionTips":["Check cache connection status before position cleanup.","Do not delete positions during/after node shutdown.","Watch logs for writer-task death and reconnect proactively."],"tags":["rust","redis","channel","position"],"backgroundTag":"broken-pipe","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}