{"record":{"id":"94a52d46e614fdfa","repo":"nautechsystems/nautilus_trader","slug":"polymarket-execution-client-is-shutting-down","errorCode":null,"errorMessage":"Polymarket execution client is shutting down","messagePattern":"Polymarket execution client is shutting down","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/polymarket/src/execution/cancellations.rs","lineNumber":417,"sourceCode":"                                venue_order_id\n                            );\n                        }\n                    }\n\n                    log::debug!(\n                        \"Cancel-all completed for instrument_id={instrument_id}: canceled={}, not_canceled={}\",\n                        response.canceled.len(),\n                        response.not_canceled.len()\n                    );\n                    Ok(())\n                }\n                Err(e) => {\n                    apply_cancel_http_failure(&e, &orders, &emitter, clock);\n                    Err(anyhow::Error::new(e).context(\"failed to cancel all orders\"))\n                }\n            }\n        });\n        anyhow::ensure!(spawned, \"Polymarket execution client is shutting down\");\n\n        Ok(())\n    }\n\n    pub(super) fn batch_cancel_orders_command(&self, cmd: &BatchCancelOrders) {\n        if cmd.cancels.is_empty() {\n            return;\n        }\n\n        let mut orders = Vec::new();\n\n        for c in &cmd.cancels {\n            if let Some(order) = self.core.cache().order(&c.client_order_id) {\n                orders.push(order.clone());\n            }\n        }\n\n        if orders.is_empty() {","sourceCodeStart":399,"sourceCodeEnd":435,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/polymarket/src/execution/cancellations.rs#L399-L435","documentation":"cancel_all_orders_command submits the batch cancellation as a spawned task; `spawned` is false when the execution client's task group refuses admission because shutdown has begun. anyhow::ensure! then fails with 'Polymarket execution client is shutting down', signalling the command was not dispatched.","triggerScenarios":"Calling cancel_all_orders after the execution client began disconnect/shutdown, so the spawn used to submit the cancel-all HTTP request is rejected and returns false.","commonSituations":"Order-management code issuing cancels during application shutdown or after disconnect was initiated; a race between a strategy teardown and an in-flight cancel-all request.","solutions":["Check the client is connected/not disconnecting before sending commands; stop strategies before disconnect()","Handle the error as 'command not sent' and re-issue after reconnect if the cancel still matters","Serialize shutdown: await disconnect completion only after all order-management commands are drained","Reconnect the client and retry cancellation for orders that may remain live on the venue"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// gate order commands on client liveness\nif not exec_client.is_connected:\n    raise RuntimeError(\"execution client not connected; refusing cancel_all\")","typeGuard":null,"tryCatchPattern":"try:\n    exec_client.cancel_all_orders(command)\nexcept Exception as e:\n    if \"shutting down\" in str(e):\n        log.warning(\"cancel-all dropped due to client shutdown; will reconcile after reconnect\")\n        pending_cancels.append(command)  # re-issue after reconnect","preventionTips":["Stop strategies and drain pending commands before initiating disconnect","Track a client liveness flag in the trading loop and skip sends when disconnecting","After reconnect, reconcile open orders with the venue and re-issue missed cancels","Keep the execution client alive longer than the strategy lifecycle"],"tags":["rust","shutdown","order-cancellation","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"}