{"record":{"id":"46374bfdc7a787b9","repo":"ipfs/kubo","slug":"error-reading-log-message-s","errorCode":null,"errorMessage":"error reading log message: %s","messagePattern":"error reading log message: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"core/corehttp/logs.go","lineNumber":44,"sourceCode":"\t\t\t\tcase <-r.Context().Done(): // Client canceled request\n\t\t\t\tcase <-n.Context().Done(): // Node shutdown\n\t\t\t\tcase <-done: // log reader goroutine exitex\n\t\t\t\t}\n\t\t\t\tpipeReader.Close()\n\t\t\t}()\n\n\t\t\terrs := make(chan error, 1)\n\n\t\t\tgo func() {\n\t\t\t\tdefer close(errs)\n\t\t\t\tdefer close(done)\n\n\t\t\t\trdr := bufio.NewReader(pipeReader)\n\t\t\t\tfor {\n\t\t\t\t\t// Read a line of log data and send it to the client.\n\t\t\t\t\tline, err := rdr.ReadString('\\n')\n\t\t\t\t\tif err != nil {\n\t\t\t\t\t\terrs <- fmt.Errorf(\"error reading log message: %s\", err)\n\t\t\t\t\t\treturn\n\t\t\t\t\t}\n\t\t\t\t\t_, err = w.Write([]byte(line))\n\t\t\t\t\tif err != nil {\n\t\t\t\t\t\t// Failed to write to client, probably disconnected.\n\t\t\t\t\t\treturn\n\t\t\t\t\t}\n\t\t\t\t\tif f, ok := w.(http.Flusher); ok {\n\t\t\t\t\t\tf.Flush()\n\t\t\t\t\t}\n\t\t\t\t\tif r.Context().Err() != nil {\n\t\t\t\t\t\treturn\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}()\n\t\t\tlog.Info(\"log API client connected\")\n\t\t\terr := <-errs\n\t\t\tif err != nil {","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/ipfs/kubo/blob/329838acdfafae224582930457efe80aa217afc0/core/corehttp/logs.go#L26-L62","documentation":"The log-streaming HTTP endpoint tails the daemon log through a pipe: a goroutine reads lines with bufio.Reader.ReadString and writes them to the HTTP response. If the read fails (pipe closed, daemon-side writer gone, EOF), the reader pushes 'error reading log message: <err>' onto an internal channel and stops streaming.","triggerScenarios":"While consuming the live log endpoint (used by `ipfs log tail`-style clients), the reading goroutine hits an error from rdr.ReadString('\\n') — e.g. the log pipe writer was closed during daemon shutdown, or an I/O error on the pipe.","commonSituations":"Daemon shutting down while a client is tailing logs; log pipe closed unexpectedly; long-lived log streams dropped when the daemon restarts; embedded usages where the log writer is torn down independently of the HTTP handler.","solutions":["Reconnect the log stream client (e.g. rerun `ipfs log tail`); the error usually means the stream ended, most often due to daemon shutdown.","Check whether the daemon is still running (`ipfs id`); restart it if it exited during the stream.","Inspect daemon logs via the on-disk log file instead of the streaming endpoint to see what happened around the failure.","If streaming repeatedly fails, report/inspect the pipe setup — a persistent read error indicates an I/O problem rather than a normal disconnect."],"exampleFix":"// before: client keeps a fragile long-lived stream\nipfs log tail  # dies with daemon\n\n// after: tolerate stream end and reconnect with backoff\nfor {\n  ipfs log tail || true\n  sleep 2\n}","handlingStrategy":"retry","validationCode":"// confirm the daemon is alive before (re)attaching a log stream\nif err := shell.NewLocalShell().ID(); err != nil {\n    return fmt.Errorf(\"daemon not reachable, not a stream problem: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"// client loop around the log stream\nfor {\n    err := tailLogs(ctx) // POST /api/v0/log/tail and stream\n    if ctx.Err() != nil { return ctx.Err() }\n    log.Printf(\"log stream ended: %v; reconnecting in 2s\", err)\n    time.Sleep(2 * time.Second)\n}","preventionTips":["Wrap log-tail clients in an auto-reconnect loop; streams legitimately end at daemon shutdown.","Stop tailing before stopping the daemon to avoid interpreting shutdown as an error.","Keep an on-disk log file fallback (GOLOG_FILE) for post-mortem when streams drop.","Treat 'error reading log message' as stream termination, not data corruption."],"tags":["logging","http","streaming","io"],"backgroundTag":"stream-read-failed","analyzedSha":"329838acdfafae224582930457efe80aa217afc0","analyzedAt":"2026-09-03T18:30:52.135Z","contentChangedAt":"2026-09-03T18:30:52.135Z","schemaVersion":2},"datasetVersion":"2026-09-11T00:17:11.886Z"}