{"record":{"id":"57321e99dc1a16dd","repo":"nautechsystems/nautilus_trader","slug":"failed-to-terminate-polymarket-execution-tasks-e","errorCode":null,"errorMessage":"Failed to terminate Polymarket execution tasks: {e}","messagePattern":"Failed to terminate Polymarket execution tasks: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/polymarket/src/execution/lifecycle.rs","lineNumber":217,"sourceCode":"\n                self.emitter.emit_order_modify_rejected(\n                    &order,\n                    Some(venue_order_id),\n                    \"Polymarket modification was interrupted during shutdown\",\n                    ts_event,\n                );\n\n                if let Some(cancel_ts) = cancel_ts\n                    && !self.fill_tracker.is_fully_filled(&venue_order_id)\n                {\n                    self.emitter\n                        .emit_order_canceled(&order, Some(venue_order_id), cancel_ts);\n                }\n            }\n        }\n\n        result\n            .map_err(|e| anyhow::anyhow!(\"Failed to terminate Polymarket execution tasks: {e}\"))?;\n        Ok(())\n    }\n\n    pub(super) async fn await_session_tasks(&self) -> anyhow::Result<()> {\n        self.session_tasks.begin_shutdown();\n        self.session_tasks\n            .finish_shutdown(TASK_SESSION_GRACEFUL_SHUTDOWN_TIMEOUT, TASK_ABORT_TIMEOUT)\n            .await\n            .map_err(|e| anyhow::anyhow!(\"Failed to terminate Polymarket session tasks: {e}\"))?;\n        Ok(())\n    }\n\n    pub(super) async fn refresh_account_state(&self) -> anyhow::Result<()> {\n        fetch_and_emit_account_state(\n            &self.http_client,\n            &self.emitter,\n            self.clock,\n            self.config.signature_type,","sourceCodeStart":199,"sourceCodeEnd":235,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/polymarket/src/execution/lifecycle.rs#L199-L235","documentation":"This error wraps a failure from `await_pending_tasks` when draining all in-flight Polymarket execution tasks during adapter teardown. It is raised by `teardown_partial_connect` and `connect_client` to convert the underlying task-group shutdown error into a contextual anyhow error, so the original cause is preserved in the `{e}` chain. It means graceful termination of execution tasks did not complete within the allowed timeouts.","triggerScenarios":"Calling teardown_partial_connect or connect_client while pending execution tasks (order submits, cancels) fail to finish or abort within TASK_PENDING_GRACEFUL_SHUTDOWN_TIMEOUT/TASK_ABORT_TIMEOUT; a spawned task hangs on I/O or a channel send with no receiver.","commonSituations":"Network outage during reconnect while orders are in flight; a hung HTTP call to the Polymarket CLOB preventing task completion; shutting down the adapter while a submit task is blocked; reconnect logic in connect_client racing slow tasks.","solutions":["Inspect the chained source error (`e.source()` / anyhow chain) for the real cause of task termination failure","Ensure the HTTP client has adequate timeouts so pending tasks cannot hang indefinitely","Avoid tearing down while tasks are mid-flight; wait for order submissions to complete or cancel them first","Check that no spawned task blocks on a channel that nobody drains","Retry connect_client after the hung task has been aborted by the abort timeout"],"exampleFix":"// before: teardown aborts mid-flight tasks\nadapter.teardown_partial_connect().await?;\n// after: drain outstanding submits before teardown\nadapter.wait_for_pending_submits().await;\nadapter.teardown_partial_connect().await?;","handlingStrategy":"try-catch","validationCode":"// check adapter state before teardown/reconnect\nif adapter.has_inflight_submits() {\n    adapter.wait_for_pending_submits().await;\n}","typeGuard":null,"tryCatchPattern":"match adapter.teardown_partial_connect().await {\n    Err(e) => { tracing::error!(\"teardown failed: {e:#}\"); /* inspect full anyhow chain */ }\n    Ok(()) => {}\n}","preventionTips":["Give HTTP calls bounded timeouts so pending tasks can always finish","Drain in-flight orders before teardown","Inspect the full anyhow error chain (:{#}) to find the root task failure"],"tags":["rust","async","shutdown","task-timeout"],"backgroundTag":"request-timeout","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"}