POLLHUP on never connected socket

Andriy Gapon avg at FreeBSD.org
Fri Sep 2 09:46:18 UTC 2011

I see a problem where FreeBSD kernel (recent head) returns POLLHUP _alone_
(0x10) for a socket that has never been connected - a client socket for which
connect(2) failed.  There is also a piece of software that doesn't expect that
flag and exhibits illogical behavior because of it.

This is how POSIX describes POLLHUP:
    The device has been disconnected. This event and POLLOUT are
mutually-exclusive; a stream can never be writable if a hangup has occurred.
However, this event and POLLIN, POLLRDNORM, POLLRDBAND, or POLLPRI are not
mutually-exclusive. This flag is only valid in the revents bitmask; it shall be
ignored in the events member.

For me "disconnected" _implies_ that the device should have been connected
first.  But this is not explicitly said anywhere.  Also, I think it's possible
that a socket gets connected and immediately disconnected (before poll(2) is
called), then the POLLHUP would be appropriate in any interpretation.
So, I am inclined to think that the software should check for POLLHUP.
But I would like to ask your opinion since the problem appears to be

Andriy Gapon

More information about the freebsd-standards mailing list