BUG/MINOR: sock: handle a weird condition with connect()

As reported on github issue #2491, there's a very strange situation where
epoll_wait() appears to be reported EPOLLERR only (and not IN/OUT/HUP etc
as normally happens with EPOLLERR), and when connect() is called again to
check the state of the ongoing connection, it returns EALREADY, basically
saying "no news, please wait". This obviously triggers a wakeup loop. For
now it has remained impossible to reproduce this issue outside of the
reporter's environment, but that's definitely something that is impossible
to get out from.

The workaround here is to address the lowest level cause we can act on,
which is to avoid returning to wait if EPOLLERR was returned. Indeed, in
this case we know it will loop, so we must definitely take this one into
account. We only do that after connect() asks us to wait, so that a
properly established connection with a queued error at the end of an
exchange will not be diverted and will be handled as usual.

This should be backported to approximately all versions, at least as far
as 2.4 according to the reporter who observed it there.

Thanks to @donnyxray for their useful captures isolating the problem.

(cherry picked from commit b4734c2bd7981846142ecabe3490bbf356993b08)
Signed-off-by: Amaury Denoyelle <adenoyelle@haproxy.com>
(cherry picked from commit 7f9161db159a78a54cf608a8bba6cb4f9ad6d359)
Signed-off-by: Amaury Denoyelle <adenoyelle@haproxy.com>
(cherry picked from commit 46dabccbba6b53de336a6de4870e46c835589bde)
Signed-off-by: Amaury Denoyelle <adenoyelle@haproxy.com>
(cherry picked from commit c93a7f854c2ce22d19fb6edd4d7ba4ca14ece163)
Signed-off-by: Amaury Denoyelle <adenoyelle@haproxy.com>
1 file changed