{"id":"95971ac3f557b4bf","repo":"gofiber/fiber","slug":"sse-write-comment-w","errorCode":null,"errorMessage":"sse: write comment: %w","messagePattern":"sse: write comment: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"info","filePath":"middleware/sse/event.go","lineNumber":82,"sourceCode":"\t}\n\tframe.WriteByte('\\n') //nolint:errcheck // bytes.Buffer writes never fail.\n\tif _, err := w.Write(frame.Bytes()); err != nil {\n\t\treturn fmt.Errorf(\"sse: write event: %w\", err)\n\t}\n\treturn nil\n}\n\nfunc writeComment(w *bufio.Writer, comment string) error {\n\tcomment = sanitizeComment(comment)\n\tif comment == \"\" {\n\t\tif _, err := w.WriteString(\":\\n\\n\"); err != nil {\n\t\t\treturn fmt.Errorf(\"sse: write heartbeat: %w\", err)\n\t\t}\n\t\treturn nil\n\t}\n\tfor line := range strings.SplitSeq(comment, \"\\n\") {\n\t\tif _, err := fmt.Fprintf(w, \": %s\\n\", line); err != nil {\n\t\t\treturn fmt.Errorf(\"sse: write comment: %w\", err)\n\t\t}\n\t}\n\tif _, err := w.WriteString(\"\\n\"); err != nil {\n\t\treturn fmt.Errorf(\"sse: finish comment: %w\", err)\n\t}\n\treturn nil\n}\n\ntype eventPayload struct {\n\tdata    string\n\thasData bool\n}\n\nfunc eventData(data any, jsonMarshal utils.JSONMarshal) (eventPayload, error) {\n\tswitch value := data.(type) {\n\tcase nil:\n\t\treturn eventPayload{}, nil\n\tcase string:","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/gofiber/fiber/blob/9a4c7e57fe0b080a04235d28a4b0d2b4b353d58c/middleware/sse/event.go#L64-L100","documentation":"Writing a comment line (': text') to the SSE stream failed at fmt.Fprintf, indicating the client connection is closed or broken. Functionally identical to the other SSE write errors but reached via the Comment() path.","triggerScenarios":"Calling stream.Comment(text) after the client disconnected, or while the connection is resetting.","commonSituations":"Using Comment for keep-alive/debug annotations on long-lived streams that clients abandon.","solutions":["Stop sending once the stream reports an error or Done() is closed.","Treat comment write failures as terminal for the stream, same as event writes."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := stream.Comment(\"ping\"); err != nil {\n    return // stream closed by client\n}","preventionTips":["Treat any write error (event/comment/heartbeat) as stream termination.","Avoid busy-looping comments; rely on the built-in heartbeat."],"tags":["sse","network","fiber"],"analyzedSha":"9a4c7e57fe0b080a04235d28a4b0d2b4b353d58c","analyzedAt":"2026-08-04T21:44:03.395Z","schemaVersion":2}