go io_error ai_generated true

panic: write to closed pipe

ID: go/io-write-to-closed-pipe

Also available as: JSON · Markdown · 中文
80%Fix Rate
85%Confidence
0Evidence
2026-04-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
1.20 active
1.21 active

Root Cause

Writing to a pipe after the read end has been closed, often due to premature closure of the reader.

generic

中文

在读取端关闭后写入管道,通常由于读取器过早关闭。

Workarounds

  1. 90% success Use io.Pipe with proper error handling and synchronization
    pr, pw := io.Pipe()
    // writer goroutine
    go func() {
        defer pw.Close()
        _, err := pw.Write(data)
        if err != nil { log.Println(err) }
    }()
    // reader
    data, err := io.ReadAll(pr)

Dead Ends

Common approaches that don't work:

  1. Ignoring SIGPIPE signal 60% fail

    Signal handling may not prevent panic; use proper synchronization.