{"record":{"id":"1b4aeaecc852a3f6","repo":"nautechsystems/nautilus_trader","slug":"load-state-channel-closed-e","errorCode":null,"errorMessage":"load_state channel closed: {e}","messagePattern":"load_state channel closed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/infrastructure/src/redis/cache.rs","lineNumber":1293,"sourceCode":"\n        get_runtime().spawn(async move {\n            let result = async {\n                let full_key = format!(\"{trader_key}{REDIS_DELIMITER}{key}\");\n                let value: Option<Bytes> = con.get(&full_key).await?;\n                let Some(value) = value else {\n                    return Ok(AHashMap::new());\n                };\n\n                DatabaseQueries::deserialize_payload(encoding, &value)\n            }\n            .await;\n\n            if let Err(e) = tx.send(result) {\n                log::error!(\"Failed to send state load result for '{key}': {e:?}\");\n            }\n        });\n\n        blocking_recv(&rx).map_err(|e| anyhow::anyhow!(\"load_state channel closed: {e}\"))?\n    }\n\n    fn update_state(&self, key: String, state: &AHashMap<String, Bytes>) -> anyhow::Result<()> {\n        let payload = DatabaseQueries::serialize_payload(self.encoding(), state)?;\n        self.database.insert(key, Some(vec![Bytes::from(payload)]))\n    }\n\n    fn replace_list(&self, key: String, payload: Bytes) -> anyhow::Result<()> {\n        self.send_command(DatabaseOperation::ReplaceList, key, Some(vec![payload]))\n    }\n}\n\n#[async_trait::async_trait]\nimpl CacheDatabaseFactory for RedisCacheConfig {\n    async fn create(\n        &self,\n        trader_id: TraderId,\n        instance_id: UUID4,","sourceCodeStart":1275,"sourceCodeEnd":1311,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/infrastructure/src/redis/cache.rs#L1275-L1311","documentation":"`load_state` offloads Redis reads to a blocking worker thread and waits for the result over a `tokio::sync::mpsc` channel. This error means the receiver side (`blocking_recv`) returned `RecvError`, i.e. the channel closed because the sending task was dropped without sending a result — the worker thread panicked or exited early.","triggerScenarios":"The background task spawned inside `load_state` panics before `tx.send(result)` (e.g. deserialization panic, poisoned mutex, OOM), or the task is dropped/aborted, so `rx` yields `Err(RecvError)`.","commonSituations":"Redis data in an unexpected format causing a panic in the loader task; async runtime shutdown during process exit; bugs in a forked/patched version of the cache where the spawned task fails silently (the original send failure is only logged, not surfaced).","solutions":["Check application logs for 'Failed to send state load result' or a panic message from the worker thread just before this error — that reveals the root cause","Retry the load; transient panics during shutdown usually clear on a fresh run","Validate the Redis keys/state payloads for the given key deserialize with the configured encoding before loading","If reproducible, wrap the worker body in catch_unwind or report send failures through the channel instead of only logging"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"// Rust\nmatch cache.load_state(key) {\n    Ok(state) => state,\n    Err(e) if e.to_string().contains(\"channel closed\") => {\n        log::error!(\"worker died loading state {key}: {e:#}; retrying once\");\n        cache.load_state(key)?\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Check logs for worker panics/send failures before this error — it is always a symptom, never the root cause","Validate Redis payloads deserialize with the configured encoding before load","Avoid triggering loads during runtime shutdown","Ensure spawned worker tasks cannot panic silently (guard deserialization with fallible APIs)"],"tags":["redis","channel","async","state"],"backgroundTag":"channel-closed","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"}