{"record":{"id":"feb0b6aa1674c235","repo":"JuliusBrussee/caveman","slug":"native-runtime-remove-stale-socket-w","errorCode":null,"errorMessage":"native runtime remove stale socket: %w","messagePattern":"native runtime remove stale socket: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"proxy/internal/nativeruntime/server_unix.go","lineNumber":49,"sourceCode":"// the coding agent or the provider proxy.\nfunc ServeUnix(ctx context.Context, path string, runtime *Runtime) error {\n\tif runtime == nil || runtime.store == nil {\n\t\treturn errors.New(\"native runtime: store is required\")\n\t}\n\tif err := os.MkdirAll(filepath.Dir(path), 0o700); err != nil {\n\t\treturn fmt.Errorf(\"native runtime mkdir: %w\", err)\n\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 {","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/proxy/internal/nativeruntime/server_unix.go#L31-L67","documentation":"When the socket path already exists, ServeUnix probes it: if a connect succeeds the socket is live (different error), otherwise the leftover file is stale and is removed. If os.Remove of that stale socket fails, the error is wrapped as \"native runtime remove stale socket\". This prevents orphaned socket files from blocking startup.","triggerScenarios":"os.Remove(path) fails on a leftover socket file: it is owned by another user, the containing directory is not writable, or the path became immutable.","commonSituations":"Previous runtime crashed leaving a socket, and restart happens under a different user or with a read-only directory; manual files placed at the socket path.","solutions":["Manually delete the stale socket file: rm <socket path>","Ensure the containing directory is writable by the current user","Run the runtime as the same user that created the leftover socket"],"exampleFix":"// before (fails on stale socket owned by other user)\nServeUnix(ctx, \"/home/olduser/.caveman/rt.sock\", rt)\n// after\nsudo rm /home/olduser/.caveman/rt.sock\nServeUnix(ctx, \"/home/newuser/.caveman/rt.sock\", rt)","handlingStrategy":"validation","validationCode":"if st, err := os.Stat(socketPath); err == nil {\n\tif err := os.Remove(socketPath); err != nil {\n\t\treturn fmt.Errorf(\"cannot clear stale socket %s: %w\", socketPath, err)\n\t}\n}","typeGuard":null,"tryCatchPattern":"if err := nativeruntime.ServeUnix(ctx, path, rt); err != nil {\n\tif strings.Contains(err.Error(), \"remove stale socket\") {\n\t\tos.Remove(path) // or log with elevated instructions\n\t}\n\treturn err\n}","preventionTips":["Use a consistent run user so leftover sockets are always removable","Add shutdown hooks to remove sockets cleanly","Keep the socket directory writable only by the runtime user"],"tags":["filesystem","socket","cleanup"],"backgroundTag":"file-write-failed","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"}