{"record":{"id":"4777137fefaabfa4","repo":"crowdsecurity/crowdsec","slug":"terminating-crowdsec-daemon-w","errorCode":null,"errorMessage":"terminating crowdsec daemon: %w","messagePattern":"terminating crowdsec daemon: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"pkg/hubtest/hubtest_item.go","lineNumber":444,"sourceCode":"\t\t\tif err != nil {\n\t\t\t\tlog.Errorf(\"unable to read crowdsec log file '%s': %s\", crowdsecLogFile, err)\n\t\t\t}\n\t\t}\n\t} else {\n\t\tif err == nil {\n\t\t\tt.Success = true\n\t\t} else {\n\t\t\tlog.Errorf(\"Appsec test %s failed:  %s\", t.Name, err)\n\n\t\t\terr = t.ImprovedLogDisplay(crowdsecLogFile)\n\t\t\tif err != nil {\n\t\t\t\tlog.Errorf(\"unable to read crowdsec log file '%s': %s\", crowdsecLogFile, err)\n\t\t\t}\n\t\t}\n\t}\n\n\tif err := crowdsecDaemon.Process.Kill(); err != nil {\n\t\treturn fmt.Errorf(\"terminating crowdsec daemon: %w\", err)\n\t}\n\n\treturn nil\n}\n\nfunc createDirs(dirs []string) error {\n\tfor _, dir := range dirs {\n\t\tif err := os.MkdirAll(dir, os.ModePerm); err != nil {\n\t\t\treturn fmt.Errorf(\"unable to create directory '%s': %w\", dir, err)\n\t\t}\n\t}\n\n\treturn nil\n}\n\nfunc (t *HubTestItem) RunWithLogFile(ctx context.Context) error {\n\ttestPath := filepath.Join(t.HubTestPath, t.Name)\n\tif _, err := os.Stat(testPath); os.IsNotExist(err) {","sourceCodeStart":426,"sourceCodeEnd":462,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/hubtest/hubtest_item.go#L426-L462","documentation":"At the end of RunWithNucleiTemplate the crowdsec daemon child process is killed with crowdsecDaemon.Process.Kill(); if that fails the test returns this error. On Linux this is rare (typically ESRCH if the process already exited), but on Windows process-kill semantics differ and failures are more common.","triggerScenarios":"crowdsecDaemon.Process.Kill() errors: the daemon already exited (process reaped/ESRCH-like condition), or OS-specific kill restrictions.","commonSituations":"Crowdsec daemon crashed during the test and already exited when teardown ran; running tests in environments with restrictive process controls; leaked daemons from earlier failed runs leaving PID state odd.","solutions":["Ignore benign 'process already finished' kills — treat daemon exit during test as a separate startup failure to investigate","Check the crowdsec log output printed earlier for why the daemon exited early","Use CommandContext with a timeout so cleanup is handled by context cancellation as a fallback","On Windows-specific failures, run the test suite on linux or guard the kill with os.Process.Signal handling"],"exampleFix":"// before\nif err := crowdsecDaemon.Process.Kill(); err != nil {\n\treturn fmt.Errorf(\"terminating crowdsec daemon: %w\", err)\n}\n// after\nif err := crowdsecDaemon.Process.Kill(); err != nil && !errors.Is(err, os.ErrProcessDone) {\n\treturn fmt.Errorf(\"terminating crowdsec daemon: %w\", err)\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := crowdsecDaemon.Process.Kill(); err != nil && !errors.Is(err, os.ErrProcessDone) {\n\tlog.Printf(\"non-fatal daemon kill failure: %v\", err)\n}","preventionTips":["Treat 'process already finished' kills as benign","Use CommandContext so cancelled contexts clean up children automatically"],"tags":["subprocess","cleanup","crowdsec","test-harness"],"backgroundTag":"process-kill-failed","analyzedSha":"909b5157986a2b2c2163300fdaef5ed01289f7d2","analyzedAt":"2026-09-06T12:27:26.012Z","contentChangedAt":"2026-09-06T12:27:26.012Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}