{"record":{"id":"e4806eccf1dc1590","repo":"nautechsystems/nautilus_trader","slug":"failed-to-start-market-shard-forwarder-e-start","errorCode":null,"errorMessage":"Failed to start market shard forwarder: {e}; startup rollback failed: {close_error}","messagePattern":"Failed to start market shard forwarder: (.+?); startup rollback failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/polymarket/src/websocket/pool.rs","lineNumber":672,"sourceCode":"        client.connect().await?;\n\n        let handle = client.clone_subscription_handle();\n        let rx = client\n            .take_message_receiver()\n            .ok_or_else(|| anyhow::anyhow!(\"Market shard receiver unavailable after connect\"))?;\n        let forwarder = match self.spawn_forwarder(rx, is_primary) {\n            Ok(forwarder) => forwarder,\n            Err((e, forwarder)) => {\n                let shard = Box::new(ShardEntry {\n                    client,\n                    handle,\n                    forwarder,\n                    owned: 0,\n                    closing: true,\n                });\n\n                if let Err(close_error) = self.close_shard(id, shard).await {\n                    anyhow::bail!(\n                        \"Failed to start market shard forwarder: {e}; startup rollback failed: \\\n                         {close_error}\"\n                    );\n                }\n                anyhow::bail!(\"Failed to start market shard forwarder: {e}\");\n            }\n        };\n\n        let shard = ShardEntry {\n            client,\n            handle,\n            forwarder,\n            owned: 0,\n            closing: false,\n        };\n        let rejected_shard = {\n            let mut state = self.state.lock();\n","sourceCodeStart":654,"sourceCodeEnd":690,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/polymarket/src/websocket/pool.rs#L654-L690","documentation":"After opening a new shard, connect_new_shard spawns a message forwarder task that pumps shard messages into the merged pool stream. If spawning the forwarder fails ({e}), the freshly opened shard is closed as a rollback; if that close also fails ({close_error}), both errors are combined into this message; otherwise the single forwarder error is raised.","triggerScenarios":"Forwarder task spawn/start fails (e.g., tokio spawn failure, runtime shutting down, channel setup failure) on a newly connected shard; rollback close of that shard also errors.","commonSituations":"Runtime shutdown while the pool is expanding capacity; resource exhaustion (task/channel limits); connection established but the message-pumping infrastructure failed to start.","solutions":["Inspect {e} for the forwarder root cause (often runtime shutdown — check the tokio runtime is alive)","If {close_error} indicates a dead connection, cleanup can be ignored; the shard never entered service","Retry the subscription after confirming the runtime/runtime handle is valid","Avoid opening shards during application shutdown; tear down the pool instead"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// ensure a live runtime before shard expansion\nassert!(!tokio::runtime::Handle::try_current().is_err(), \"no runtime\");","typeGuard":null,"tryCatchPattern":"if let Err(e) = pool.subscribe_one(asset_id).await {\n    if e.to_string().contains(\"forwarder\") {\n        log::warn!(\"shard forwarder failed: {e}\");\n        // retry after confirming runtime health\n    }\n}","preventionTips":["Keep the tokio runtime alive for the pool's lifetime","Avoid opening shards during application shutdown","Watch for resource exhaustion (task limits)","Retry subscriptions after transient spawn failures"],"tags":["websocket","polymarket","forwarder","runtime","rollback"],"backgroundTag":"internal-invariant-violation","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"}