{"record":{"id":"a6b96c0967d4679a","repo":"nautechsystems/nautilus_trader","slug":"polymarket-task-admission-is-closed-e","errorCode":null,"errorMessage":"Polymarket task admission is closed: {e}","messagePattern":"Polymarket task admission is closed: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/polymarket/src/data/lifecycle.rs","lineNumber":93,"sourceCode":"    }\n\n    fn register_message_handler(\n        &self,\n        mut rx: tokio::sync::mpsc::UnboundedReceiver<PolymarketWsMessage>,\n    ) -> anyhow::Result<()> {\n        let cancellation = self.cancellation_token.clone();\n\n        seed_token_meta_from_live_instruments(\n            self.clock.get_time_ns(),\n            &self.closed_condition_ids,\n            &self.instruments,\n            &self.token_meta,\n        );\n\n        let task_spawner = self\n            .tasks\n            .spawner()\n            .map_err(|e| anyhow::anyhow!(\"Polymarket task admission is closed: {e}\"))?;\n        let ctx = WsMessageContext {\n            clock: self.clock,\n            data_sender: self.data_sender.clone(),\n            token_meta: self.token_meta.clone(),\n            instruments: self.instruments.clone(),\n            instrument_update_state: self.instrument_update_state.clone(),\n            gamma_client: self.provider.http_client().clone(),\n            filters: self.provider.filters(),\n            order_books: self.order_books.clone(),\n            last_quotes: self.last_quotes.clone(),\n            active_quote_subs: self.active_quote_subs.clone(),\n            active_delta_subs: self.active_delta_subs.clone(),\n            active_trade_subs: self.active_trade_subs.clone(),\n            active_instrument_status_subs: self.active_instrument_status_subs.clone(),\n            active_instrument_close_subs: self.active_instrument_close_subs.clone(),\n            closed_condition_ids: self.closed_condition_ids.clone(),\n            ws_open_tokens: self.ws_open_tokens.clone(),\n            ws_sub_mutex: self.ws_sub_mutex.clone(),","sourceCodeStart":75,"sourceCodeEnd":111,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/polymarket/src/data/lifecycle.rs#L75-L111","documentation":"register_message_handler first obtains a spawner handle from the Polymarket task group via tasks.spawner(). If the task group is closed or shutting down, the spawner cannot be obtained and this error is returned, aborting WS message-handler registration during connect.","triggerScenarios":"Calling connect()/connect_client while the client's task group has begun shutdown (begin_shutdown called by a prior disconnect), so tasks.spawner() returns Err.","commonSituations":"Reconnect after an intentional disconnect in the same client generation; shutdown hook firing while connect is still executing; concurrent connect/disconnect calls from different tasks.","solutions":["Serialize client lifecycle: never call disconnect() concurrently with connect()","Create a new generation by calling connect() after shutdown completes (connect restarts the generation)","Check that application shutdown is not cancelling the client's runtime"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// Ensure no disconnect in flight before connecting\nif client.is_disconnecting() { return Err(anyhow!(\"cannot connect while disconnecting\")); }","typeGuard":null,"tryCatchPattern":"if let Err(e) = client.connect().await {\n    if e.to_string().contains(\"task admission is closed\") {\n        tokio::time::sleep(Duration::from_secs(1)).await;\n        client.connect().await?;\n    }\n}","preventionTips":["Sequence lifecycle operations with an explicit state machine (Disconnected -> Connecting -> Connected -> Disconnecting)","Await full disconnect completion before any reconnect","Avoid issuing connects from shutdown hooks","Add jittered backoff to reconnect loops"],"tags":["rust","tokio","task-group","polymarket"],"backgroundTag":"invalid-state-transition","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"}