{"record":{"id":"703771407d34afe7","repo":"microsoft/aspire","slug":"connection-timeout","errorCode":null,"errorMessage":"Connection timeout","messagePattern":"Connection timeout","errorType":"exception","errorClass":"TimeoutError","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.CodeGeneration.Python/PythonModuleBuilder.cs","lineNumber":424,"sourceCode":"\n                def close(self) -> None:\n                    '''Close the handle.'''\n                    if self._handle is not None and self._handle != self.INVALID_HANDLE_VALUE:\n                        _kernel32.CloseHandle(self._handle)\n                        self._handle = None\n\n            def _connect_pipe(socket_path: str, timeout_sec: float) -> _PipeSocket:\n                '''Connect to a named pipe with timeout, retrying until available.'''\n                pipe_path = f\"\\\\\\\\.\\\\pipe\\\\{socket_path}\"\n                _logger.debug(\"Connecting to: %s\", pipe_path)\n\n                start_time = time.time()\n                while (time.time() - start_time) < timeout_sec:\n                    try:\n                        return _PipeSocket(pipe_path)\n                    except FileNotFoundError:\n                        time.sleep(0.1)\n                raise TimeoutError(\"Connection timeout\")\n\n        else:\n            # On Unix, use socket.socket directly as the pipe socket type\n            _PipeSocket = socket.socket  # type: ignore[misc]\n\n            def _connect_pipe(socket_path: str, timeout_sec: float) -> _PipeSocket:\n                '''Connect to a Unix domain socket with timeout.'''\n                _logger.debug(\"Connecting to: %s\", socket_path)\n\n                start_time = time.time()\n                while (time.time() - start_time) < timeout_sec:\n                    try:\n                        sock = _PipeSocket(socket.AF_UNIX, socket.SOCK_STREAM)\n                        sock.settimeout(timeout_sec)\n                        sock.connect(socket_path)\n                        sock.settimeout(None)  # Set to blocking mode\n                        return sock\n                    except FileNotFoundError:","sourceCodeStart":406,"sourceCodeEnd":442,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.CodeGeneration.Python/PythonModuleBuilder.cs#L406-L442","documentation":"Raised by _connect_pipe on Windows when the generated client retried opening the named pipe (via _PipeSocket) for the full timeout window and every attempt failed with FileNotFoundError. It signals the host's pipe never appeared within the allotted time.","triggerScenarios":"Calling the client's connection entry point with a timeout_sec too small for host startup; host failing to create the pipe at all (crashed before listening); wrong pipe path causing every retry to miss.","commonSituations":"Slow machine or cold-start (container pull, restore) exceeding the default timeout; connecting in a test before the AppHost finishes booting; stale environment variable pointing at an old pipe name.","solutions":["Increase the connection timeout (timeout_sec) passed to the connect helper.","Start the host and wait for its 'listening' signal before connecting.","Verify the pipe path comes from the current host run (fresh env var/log output).","Check host startup logs for errors that prevented pipe creation."],"exampleFix":"// before\nsock = _connect_pipe(pipe_path, timeout_sec=5)\n\n// after\nsock = _connect_pipe(pipe_path, timeout_sec=60)","handlingStrategy":"retry","validationCode":"if not os.path.exists(r\"\\\\.\\pipe\" ):\n    log.warning(\"pipe namespace unavailable; host may not be running\")","typeGuard":null,"tryCatchPattern":"try:\n    sock = _connect_pipe(pipe_path, timeout_sec=60)\nexcept TimeoutError:\n    log.error(\"timed out connecting to %s; is the host running?\", pipe_path)\n    raise","preventionTips":["Set timeout_sec well above expected host startup time.","Gate connection on a host readiness event or log line.","Verify pipe path freshness on every run."],"tags":["timeout","named-pipe","windows","connection"],"backgroundTag":"request-timeout","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}