{"record":{"id":"3bbfe132407a953e","repo":"nautechsystems/nautilus_trader","slug":"gateway-not-ready-after-seconds","errorCode":null,"errorMessage":"Gateway `{}` not ready after {} seconds","messagePattern":"Gateway `(.+?)` not ready after (.+?) seconds","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/interactive_brokers/src/gateway/dockerized.rs","lineNumber":460,"sourceCode":"        let wait_time = wait.unwrap_or(self.config.timeout);\n        let mut waited = 0u64;\n\n        while waited < wait_time {\n            if self.is_logged_in(&container_id).await.unwrap_or(false) {\n                tracing::debug!(\n                    \"Gateway `{}` ready. VNC port is {:?}\",\n                    self.container_name,\n                    self.config.vnc_port\n                );\n                return Ok(());\n            }\n\n            tracing::debug!(\"Waiting for IB Gateway to start\");\n            tokio::time::sleep(Duration::from_secs(1)).await;\n            waited += 1;\n        }\n\n        anyhow::bail!(\n            \"Gateway `{}` not ready after {} seconds\",\n            self.container_name,\n            wait_time\n        )\n    }\n\n    /// Safely start the gateway, handling container already exists errors.\n    ///\n    /// # Arguments\n    ///\n    /// * `wait` - Optional wait time in seconds\n    ///\n    /// # Errors\n    ///\n    /// Returns an error if startup fails (other than container exists).\n    pub async fn safe_start(&mut self, wait: Option<u64>) -> anyhow::Result<()> {\n        match self.start(wait).await {\n            Ok(()) => Ok(()),","sourceCodeStart":442,"sourceCodeEnd":478,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/interactive_brokers/src/gateway/dockerized.rs#L442-L478","documentation":"DockerizedIBGateway::start polls the container once per second (for up to the configured timeout or an explicit wait value) checking whether the gateway reports logged-in status. If the gateway never becomes ready within that window, start bails with the container name and elapsed seconds.","triggerScenarios":"start() -> is_logged_in() keeps returning false until waited >= wait_time (config timeout or the wait argument). Commonly because IB credentials/2FA were not approved, the gateway image is slow to pull/start, or the container is crash-looping.","commonSituations":"First-time 2FA notification not confirmed in IB's mobile app; wrong trading mode (paper vs live) credentials; slow machine or cold Docker daemon exceeding the default timeout; gateway container restarting due to bad config.","solutions":["Confirm the 2FA/I.login prompt was accepted in the IB Gateway UI or mobile app (check via the container's VNC port)\nIncrease DockerizedIBGatewayConfig.timeout (or pass a larger wait to start) and retry\nCheck container logs: docker logs <container_name> for credential/config errors\nVerify the gateway image and paper/live trading mode match your credentials"],"exampleFix":"// before\nlet config = DockerizedIBGatewayConfig { timeout: 60, .. };\n// after\nlet config = DockerizedIBGatewayConfig { timeout: 300, .. }; // allow time for 2FA","handlingStrategy":"retry","validationCode":"// before starting, ensure Docker is up and image is present\n// docker info && docker image inspect <gateway_image>","typeGuard":null,"tryCatchPattern":"loop {\n    match gateway.start(Some(300)).await {\n        Ok(()) => break,\n        Err(e) if e.to_string().contains(\"not ready after\") => {\n            warn!(\"gateway not ready: {e}; retrying with longer timeout\");\n            tokio::time::sleep(Duration::from_secs(10)).await;\n        }\n        Err(e) => return Err(e),\n    }\n}","preventionTips":["Approve IB 2FA prompts promptly when starting the gateway","Set a generous timeout (5+ minutes) for cold starts and image pulls","Monitor container logs and health before assuming timeout means failure","Verify paper/live credentials match the configured trading mode"],"tags":["docker","interactive-brokers","timeout","gateway"],"backgroundTag":"request-timeout","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"}