{"record":{"id":"153d9788db5f9bc8","repo":"JuliusBrussee/caveman","slug":"native-runtime-accept-w","errorCode":null,"errorMessage":"native runtime accept: %w","messagePattern":"native runtime accept: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"proxy/internal/nativeruntime/server_unix.go","lineNumber":73,"sourceCode":"\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}\n\t\tgo serveConn(ctx, conn, runtime)\n\t}\n}\n","sourceCodeStart":55,"sourceCodeEnd":78,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/27d5a3981a347890211bb1bf2439e5c821a63bc9/proxy/internal/nativeruntime/server_unix.go#L55-L78","documentation":"Returned when listener.Accept() fails in the native runtime's Unix serve loop and the context is still alive. A normal shutdown path exists (ctx cancelled closes the listener and Accept returns nil), so this error means an unexpected accept failure: file-descriptor exhaustion, socket closed out from under the loop, or resource limits.","triggerScenarios":"Long-running Serve where the process hits its FD limit (ulimit -n) so accept(2) returns EMFILE, or an external process unlinks/closes the listening socket, or the listener is closed by anything other than the ctx-done goroutine.","commonSituations":"Leaked per-connection goroutines/files pushing the process over the fd ceiling on a busy machine; systemd socket activation or a supervisor interfering with the socket; container environments with low default RLIMIT_NOFILE.","solutions":["Check the process fd usage (ls /proc/<pid>/fd | wc -l) against ulimit -n and raise the limit or fix a leak","Verify nothing external is closing or unlinking the socket (other scripts, container supervisors)","Apply an accept backoff: on transient errors like EMFILE, sleep briefly and continue instead of returning","Restart Serve with a fresh context after the environment is corrected"],"exampleFix":"// before: any accept error other than ctx-cancel kills the server\nconn, err := listener.Accept()\nif err != nil {\n    if ctx.Err() != nil { return nil }\n    return fmt.Errorf(\"native runtime accept: %w\", err)\n}\n\n// after: tolerate transient accept errors\nconn, err := listener.Accept()\nif err != nil {\n    if ctx.Err() != nil { return nil }\n    if isTemporaryAcceptError(err) { time.Sleep(50 * time.Millisecond); continue }\n    return fmt.Errorf(\"native runtime accept: %w\", err)\n}","handlingStrategy":"try-catch","validationCode":"// Raise the fd ceiling before serving (best effort)\nvar rl syscall.Rlimit\nif syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rl) == nil && rl.Cur < 4096 {\n    rl.Cur = 4096\n    _ = syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rl)\n}","typeGuard":null,"tryCatchPattern":"err := nativeruntime.Serve(ctx, home, rt)\nvar oe *net.OpError\nif errors.As(err, &oe) && strings.Contains(err.Error(), \"native runtime accept\") {\n    if errors.Is(oe.Err, syscall.EMFILE) || errors.Is(oe.Err, syscall.ENFILE) {\n        // fd exhaustion: shed load, raise limit, restart serve loop\n    }\n}","preventionTips":["Monitor open-fd count against ulimit in long-running deployments","Close per-connection resources deterministically in serveConn","Run Serve under a supervisor that restarts it if accept fails unexpectedly"],"tags":["unix-socket","accept","file-descriptors","go"],"backgroundTag":null,"analyzedSha":"27d5a3981a347890211bb1bf2439e5c821a63bc9","analyzedAt":"2026-08-15T09:26:11.751Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}