{"record":{"id":"4cf9d1a00566d3d6","repo":"crowdsecurity/crowdsec","slug":"could-not-close-udp-connection-w","errorCode":null,"errorMessage":"could not close UDP connection: %w","messagePattern":"could not close UDP connection: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"pkg/acquisition/modules/syslog/internal/server/syslogserver.go","lineNumber":74,"sourceCode":"\t\t\t\treturn nil //nolint:nilerr  // context cancelation is not a failure\n\t\t\t}\n\n\t\t\treturn fmt.Errorf(\"reading from socket: %w\", err)\n\t\t}\n\n\t\tmsg := SyslogMessage{Message: buf[:n], Client: strings.Split(addr.String(), \":\")[0]}\n\n\t\tselect {\n\t\tcase msgChan <- msg:\n\t\tcase <-ctx.Done():\n\t\t\treturn nil\n\t\t}\n\t}\n}\n\nfunc (s *SyslogServer) KillServer() error {\n\tif err := s.conn.Close(); err != nil {\n\t\treturn fmt.Errorf(\"could not close UDP connection: %w\", err)\n\t}\n\n\treturn nil\n}\n","sourceCodeStart":56,"sourceCodeEnd":79,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/acquisition/modules/syslog/internal/server/syslogserver.go#L56-L79","documentation":"KillServer() failed to close the UDP connection. Close() on the socket returned an error, most commonly because the connection was already closed (use of closed network connection) or s.conn is in an unusable state.","triggerScenarios":"KillServer is called after the connection was already closed elsewhere (e.g. Serve aborted and a second shutdown path ran), or during teardown after a read error left the socket dead.","commonSituations":"Double shutdown during crowdsec exit; acquisition reload killing a server whose Serve loop already closed the socket; nil/failed Listen leaving conn unset in older code paths.","solutions":["Treat this as a shutdown-time warning if the underlying error is 'use of closed network connection' — the socket is already gone, which is the desired end state.","Ensure KillServer is called exactly once per Listen (check defer chains in Stream and reload logic).","If it recurs, check for races between Serve returning and the deferred KillServer in run.go."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := srv.KillServer(); err != nil {\n    if errors.Is(err, net.ErrClosed) || strings.Contains(err.Error(), \"use of closed\") {\n        return nil // already closed, acceptable at shutdown\n    }\n    return err\n}","preventionTips":["Call KillServer exactly once per successful Listen.","Use sync.Once around shutdown to make teardown idempotent.","Ignore 'already closed' errors during process exit teardown."],"tags":["network","udp","shutdown","syslog"],"backgroundTag":"connection-closed","analyzedSha":"909b5157986a2b2c2163300fdaef5ed01289f7d2","analyzedAt":"2026-09-06T12:27:26.012Z","contentChangedAt":"2026-09-06T12:27:26.012Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}