{"record":{"id":"1b4cb9dccc75bdbe","repo":"microsoft/aspire","slug":"pipe-not-found-pipe-path","errorCode":null,"errorMessage":"Pipe not found: {pipe_path}","messagePattern":"Pipe not found: (.+?)","errorType":"exception","errorClass":"FileNotFoundError","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.CodeGeneration.Python/PythonModuleBuilder.cs","lineNumber":329,"sourceCode":"                ERROR_IO_PENDING = 997\n                ERROR_FILE_NOT_FOUND = 2\n\n                def __init__(self, pipe_path: str) -> None:\n                    self._handle: int | None = None\n                    handle = _kernel32.CreateFileW(\n                        pipe_path,\n                        self.GENERIC_READ | self.GENERIC_WRITE,\n                        0,  # no sharing\n                        None,  # default security\n                        self.OPEN_EXISTING,\n                        self.FILE_FLAG_OVERLAPPED,  # match server's async mode\n                        None  # no template\n                    )\n\n                    if handle == self.INVALID_HANDLE_VALUE:\n                        error = ctypes.get_last_error()\n                        if error == self.ERROR_FILE_NOT_FOUND:\n                            raise FileNotFoundError(f\"Pipe not found: {pipe_path}\")\n                        raise OSError(f\"CreateFile failed with error {error}\")\n\n                    self._handle = handle\n\n                def _create_overlapped_event(self) -> _OVERLAPPED:\n                    '''Create an OVERLAPPED structure with an event for async I/O.'''\n                    overlapped = _OVERLAPPED()\n                    overlapped.hEvent = _kernel32.CreateEventW(None, True, False, None)\n                    return overlapped\n\n                def recv(self, n: int) -> bytes:\n                    '''Read up to n bytes using overlapped I/O.'''\n                    buffer = ctypes.create_string_buffer(n)\n                    bytes_read = wintypes.DWORD()\n                    overlapped = self._create_overlapped_event()\n\n                    try:\n                        success = _kernel32.ReadFile(","sourceCodeStart":311,"sourceCodeEnd":347,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.CodeGeneration.Python/PythonModuleBuilder.cs#L311-L347","documentation":"On Windows the generated Python module connects to the host over a named pipe using CreateFile via ctypes. When CreateFile fails with ERROR_FILE_NOT_FOUND, the pipe wrapper raises FileNotFoundError with the pipe path. It means no server is currently listening on that pipe endpoint.","triggerScenarios":"Calling the generated client's connect/API entry point while the Aspire host (pipe server) has not started yet, has exited, or the pipe path passed to _connect_pipe is wrong or stale.","commonSituations":"Racing the host startup (client starts before AppHost creates the pipe); the host process crashed; running from a different user session (named pipe namespace per-session); connecting with an old pipe name after the app was restarted.","solutions":["Ensure the Aspire host / AppHost is running before creating the client.","Retry with backoff on FileNotFoundError — _connect_pipe already retries until timeout_sec; increase the timeout if startup is slow.","Verify the pipe path matches what the host exported (env var/log line) — a mismatched path will never be found.","Check host logs for a crash during startup."],"exampleFix":"// before\nclient = RpcClient.connect()  # host not up yet -> FileNotFoundError\n\n// after\nclient = RpcClient.connect(timeout_sec=30)  # wait longer for host pipe to appear","handlingStrategy":"retry","validationCode":"pipe_path = os.environ.get(\"ASPIRE_PIPE_PATH\")\nif not pipe_path:\n    raise RuntimeError(\"ASPIRE_PIPE_PATH not set; host not started?\")","typeGuard":null,"tryCatchPattern":"try:\n    client = RpcClient.connect(pipe_path, timeout_sec=60)\nexcept FileNotFoundError:\n    log.error(\"host pipe %s never appeared\", pipe_path)\n    raise","preventionTips":["Wait for a host readiness signal before connecting.","Pass a generous timeout_sec covering worst-case startup.","Always source the pipe path from the current host run."],"tags":["named-pipe","windows","connection","python"],"backgroundTag":"connection-refused","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"}