Skip to content

net: 0-byte read from TCP connection always return EOF #10940

Closed
@huguesb

Description

@huguesb

My understanding is that the recommended way to test whether a TCP connection has been closed by the remote peer is to do a 0-byte read from the socket, which would return EOF if the remote peer sent a FIN.

Unfortunately that doesn't work in go as netFD.Read always return EOF when 0 bytes are read, regardless of the requested read size.

Is that on purpose? Is there another way to detect reception of a FIN? This matters to me because I need to stream data to a write-only raw TCP endpoint that I don't control and the first Write on a closed connection often silently fails, potentially resulting in data loss.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions