{"record":{"id":"1d894912f87debcc","repo":"microsoft/typescript-go","slug":"failed-to-create-api-transport-w","errorCode":null,"errorMessage":"failed to create API transport: %w","messagePattern":"failed to create API transport: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/lsp/server.go","lineNumber":1868,"sourceCode":"\n\tif s.apiSessions == nil {\n\t\ts.apiSessions = make(map[string]*api.Session)\n\t}\n\n\tvar apiSession *api.Session\n\tapiSession = api.NewSession(s.session, nil)\n\n\t// Use provided pipe path or generate a unique one\n\tvar pipePath string\n\tif params.Pipe != nil && *params.Pipe != \"\" {\n\t\tpipePath = *params.Pipe\n\t} else {\n\t\tpipePath = s.generateAPIPipePath()\n\t}\n\n\ttransport, err := api.NewPipeTransport(pipePath)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to create API transport: %w\", err)\n\t}\n\n\t// Start accepting connections in the background\n\tgo func() {\n\t\tdefer func() {\n\t\t\tapiSession.Close()\n\t\t\ts.removeAPISession(apiSession.ID())\n\t\t}()\n\n\t\trwc, acceptErr := transport.Accept()\n\t\t_ = transport.Close()\n\t\tif acceptErr != nil {\n\t\t\ts.logger.Errorf(\"API session %s: failed to accept connection: %v\", apiSession.ID(), acceptErr)\n\t\t\treturn\n\t\t}\n\n\t\t// Create a cancellable context for the API connection\n\t\tapiCtx, apiCancel := context.WithCancel(s.backgroundCtx)","sourceCodeStart":1850,"sourceCodeEnd":1886,"githubUrl":"https://github.com/microsoft/typescript-go/blob/1bcfa18d79a3be41772223d5c05dfe4480e614ff/internal/lsp/server.go#L1850-L1886","documentation":"Returned when the API session setup fails at api.NewPipeTransport, i.e. the OS-level listener could not be created on the pipe path. On Unix this creates a Unix domain socket; on Windows a named pipe. Typical underlying failures: the socket path exceeds the kernel limit (~104-108 bytes for sun_path), a stale socket file already occupies the address, the parent directory does not exist or is not writable, or Windows rejects the pipe name format.","triggerScenarios":"Calling the API-session request with no Pipe param so the generated path is long; passing a Pipe path whose parent dir was deleted; leftover socket file from a crashed previous run; running in a sandboxed/container env where the default temp dir forbids socket creation; Windows path missing the \\\\.\\pipe\\ prefix form.","commonSituations":"Long TMPDIR paths in CI containers; multiple server instances colliding on a fixed pipe path; permissions in restricted service accounts; macOS tmp cleanup removing the directory mid-session.","solutions":["Pass an explicit, short Pipe path in a directory you know is writable (params.Pipe)","If reusing a fixed path, unlink/remove the stale socket file before starting (Unix)","Verify the parent directory exists and the process has create permissions","On Windows, use a valid \\\\.\\pipe\\name form; on Unix keep the absolute path under ~100 chars"],"exampleFix":"// before\nparams := &lsproto.OpenApiSessionParams{} // auto-generated path\n\n// after\np := \"/tmp/api-\" + pid\nos.Remove(p) // clear stale socket\nparams := &lsproto.OpenApiSessionParams{Pipe: &p}","handlingStrategy":"validation","validationCode":"// Unix: keep socket path short and pre-clear stale files\nif len(pipePath) > 100 {\n\tpipePath = filepath.Join(\"/tmp\", fmt.Sprintf(\"api-%d\", os.Getpid()))\n}\nos.Remove(pipePath) // stale socket from a previous run\nif dir := filepath.Dir(pipePath); dir != \".\" {\n\t_ = os.MkdirAll(dir, 0o755)\n}","typeGuard":null,"tryCatchPattern":"transport, err := api.NewPipeTransport(pipePath)\nif err != nil {\n\t// one retry with a fresh short path in temp dir\n\tpipePath = filepath.Join(os.TempDir(), fmt.Sprintf(\"api-%d-%d\", os.Getpid(), time.Now().UnixNano()))\n\ttransport, err = api.NewPipeTransport(pipePath)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to create API transport: %w\", err)\n\t}\n}","preventionTips":["Always pass an explicit short Pipe path in a writable directory","Remove stale socket files before binding the same path again","On Windows use the \\\\.\\pipe\\ namespace; on Unix stay under the ~104-byte sun_path limit"],"tags":["pipe","unix-socket","named-pipe","api-session","filesystem"],"backgroundTag":null,"analyzedSha":"1bcfa18d79a3be41772223d5c05dfe4480e614ff","analyzedAt":"2026-08-16T02:12:00.115Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}