Skip to content

net: Checking errors for EPIPE and ECONNRESET requires syscall #8319

Open
@PieterD

Description

@PieterD
Reading and writing can cause EPIPE and ECONNRESET to be returned in addition to io.EOF.

_, err := conn.Write(data)
if oe, ok := err.(*net.OpError); ok && (oe.Err == syscall.EPIPE || oe.Err ==
syscall.ECONNRESET) {
    return fmt.Errorf("Connection closed")
}

_, err := conn.Read(data)
oe, ok := err.(*net.OpError)
if err == io.EOF || ok && oe.Err == syscall.ECONNRESET {
    return fmt.Errorf("Connection closed")
}

This isn't the neatest solution, and if we're going to freeze and possibly internalize
syscall, this is going to have to go.

Perhaps something similar to os.IsExist? I'm thinking net.IsReset or net.IsClosed.

Or we could simply return io.EOF for both. I don't know.

And what about other operating systems? Do they have similar problems?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions