{"record":{"id":"44058c79dbd7cd92","repo":"JuliusBrussee/caveman","slug":"native-runtime-listen-w","errorCode":null,"errorMessage":"native runtime listen: %w","messagePattern":"native runtime listen: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"proxy/internal/nativeruntime/server_unix.go","lineNumber":56,"sourceCode":"\t}\n\tif err := os.Chmod(filepath.Dir(path), 0o700); err != nil {\n\t\treturn fmt.Errorf(\"native runtime chmod dir: %w\", err)\n\t}\n\tif _, err := os.Stat(path); err == nil {\n\t\tconn, dialErr := net.DialTimeout(\"unix\", path, 50*time.Millisecond)\n\t\tif dialErr == nil {\n\t\t\t_ = conn.Close()\n\t\t\treturn errors.New(\"native runtime: socket already active\")\n\t\t}\n\t\tif err := os.Remove(path); err != nil {\n\t\t\treturn fmt.Errorf(\"native runtime remove stale socket: %w\", err)\n\t\t}\n\t} else if !os.IsNotExist(err) {\n\t\treturn fmt.Errorf(\"native runtime inspect socket: %w\", err)\n\t}\n\tlistener, err := net.Listen(\"unix\", path)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"native runtime listen: %w\", err)\n\t}\n\tdefer listener.Close()\n\tdefer os.Remove(path)\n\tif err := os.Chmod(path, 0o600); err != nil {\n\t\treturn fmt.Errorf(\"native runtime chmod socket: %w\", err)\n\t}\n\tgo func() {\n\t\t<-ctx.Done()\n\t\t_ = listener.Close()\n\t}()\n\tfor {\n\t\tconn, err := listener.Accept()\n\t\tif err != nil {\n\t\t\tif ctx.Err() != nil {\n\t\t\t\treturn nil\n\t\t\t}\n\t\t\treturn fmt.Errorf(\"native runtime accept: %w\", err)\n\t\t}","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/proxy/internal/nativeruntime/server_unix.go#L38-L74","documentation":"After clearing stale socket state, ServeUnix calls net.Listen(\"unix\", path) to bind the socket. Any bind failure is wrapped as \"native runtime listen\". Common causes are the path being in use by a live listener or permission problems on the directory.","triggerScenarios":"net.Listen(\"unix\", path) errors: another live process already holds the socket path (address in use), the directory is not writable, or the path exceeds the unix socket length limit.","commonSituations":"Two runtime instances launched simultaneously; leftover socket from a hung process that still answers probes; running in a sandbox with a restricted socket directory.","solutions":["Stop the other process bound to the socket (pgrep/lsof) before starting the runtime","Use a unique socket path per instance or per user","Shorten the path so it fits the 108-byte unix socket limit"],"exampleFix":"// before\nServeUnix(ctx, \"/tmp/a/very/long/path/exceeding/limits/nativeruntime.sock\", rt)\n// after\nServeUnix(ctx, \"/tmp/nativeruntime.sock\", rt)","handlingStrategy":"retry","validationCode":"if conn, err := net.DialTimeout(\"unix\", socketPath, 50*time.Millisecond); err == nil {\n\tconn.Close()\n\treturn errors.New(\"runtime socket already active\")\n}","typeGuard":null,"tryCatchPattern":"err := nativeruntime.ServeUnix(ctx, path, rt)\nif err != nil {\n\tif strings.Contains(err.Error(), \"listen\") {\n\t\t// wait for the holder to exit, then retry once\n\t\ttime.Sleep(500 * time.Millisecond)\n\t\treturn nativeruntime.ServeUnix(ctx, path, rt)\n\t}\n\treturn err\n}","preventionTips":["Use a supervisor/lock so only one runtime instance starts per socket","Pick a per-user unique socket path","Check for live holders with lsof before starting"],"tags":["network","socket","listen"],"backgroundTag":"address-already-in-use","analyzedSha":"3ee70a102609e550bd2e68004bf5990a9341c851","analyzedAt":"2026-09-20T15:53:39.229Z","contentChangedAt":"2026-09-20T15:53:39.229Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}