{"record":{"id":"be2a20274ebff071","repo":"lima-vm/lima","slug":"failed-to-stop-usernet-q-w","errorCode":null,"errorMessage":"failed to stop usernet %#q: %w","messagePattern":"failed to stop usernet %#q: %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/networks/reconcile/reconcile.go","lineNumber":402,"sourceCode":"\n// stderrHint returns the daemon's stderr (or a pointer to the log) to append to errors.\nfunc stderrHint(stderrLog string) string {\n\tif b, err := os.ReadFile(stderrLog); err == nil && len(b) > 0 {\n\t\treturn fmt.Sprintf(\" (stderr: %s)\", strings.TrimSpace(string(b)))\n\t}\n\treturn fmt.Sprintf(\" (check %#q)\", stderrLog)\n}\n\nfunc stopNetwork(ctx context.Context, cfg *networks.Config, name string) error {\n\tlogrus.Debugf(\"Make sure %#q network is stopped\", name)\n\t// Handle usernet first without sudo requirements\n\tisUsernet, err := cfg.Usernet(name)\n\tif err != nil {\n\t\treturn err\n\t}\n\tif isUsernet {\n\t\tif err := usernet.Stop(ctx, name); err != nil {\n\t\t\treturn fmt.Errorf(\"failed to stop usernet %#q: %w\", name, err)\n\t\t}\n\t\treturn nil\n\t}\n\n\tif runtime.GOOS != \"darwin\" {\n\t\treturn nil\n\t}\n\n\t// Don't call validateConfig() until we actually need to stop a daemon because\n\t// stopNetwork() may be called even when the daemons are not installed.\n\tfor _, daemon := range []string{networks.SocketVMNet} {\n\t\tif ok, _ := cfg.IsDaemonInstalled(daemon); !ok {\n\t\t\tcontinue\n\t\t}\n\t\tpid, _ := store.ReadPIDFile(cfg.PIDFile(name, daemon))\n\t\tif pid != 0 {\n\t\t\tlogrus.Infof(\"Stopping %s daemon for %#q network\", daemon, name)\n\t\t\tif err := validateConfig(ctx, cfg); err != nil {","sourceCodeStart":384,"sourceCodeEnd":420,"githubUrl":"https://github.com/lima-vm/lima/blob/dd909d0973cd84fa35f9e1693181b4585ea616c1/pkg/networks/reconcile/reconcile.go#L384-L420","documentation":"Lima could not stop the running userspace network (usernet/vde) daemon for the given network when reconciling networks down. The underlying error from usernet.Stop (process kill/HTTP request to the usernet controller) is wrapped verbatim.","triggerScenarios":"Reconcile → stopNetwork for a network whose cfg.Usernet(name) is true, and usernet.Stop returns an error — e.g. the usernet controller process cannot be killed or its HTTP endpoint is unresponsive.","commonSituations":"An usernet daemon already crashed but the process entry is inconsistent, the usernet process is owned by another user, or the context was cancelled mid-stop.","solutions":["Read the wrapped cause to see if the process is already gone; if so, remove the stale PID file under ~/.lima and retry","Manually kill the leftover usernet/vde process, then run limactl start again (it reconciles state)","Check that no other user session owns the usernet process","Retry after the transient condition clears (e.g. system under heavy load)"],"exampleFix":"// before\npgrep -af usernet\nkill <pid>\nrm ~/.lima/networks/*_pid\n// after\nlimactl start","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := stopNetwork(ctx, name); err != nil {\n    log.Warnf(\"usernet stop failed: %v; cleaning up manually\", err)\n    // pkill usernet/vde, remove stale PID files, continue reconciliation\n}","preventionTips":["Don't kill usernet processes as a different user","Stop instances with limactl stop so state stays consistent","Clean stale PID files after abnormal exits","Check the wrapped cause — 'already stopped' errors are usually safe to ignore"],"tags":["network","usernet","daemon-stop","process-kill"],"backgroundTag":"daemon-stop-failed","analyzedSha":"dd909d0973cd84fa35f9e1693181b4585ea616c1","analyzedAt":"2026-09-01T14:24:59.842Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}