lib/async_req: make sure we return errors early from async_connect_send/recv
authorStefan Metzmacher <metze@samba.org>
Wed, 2 Oct 2019 14:56:30 +0000 (07:56 -0700)
committerJeremy Allison <jra@samba.org>
Wed, 26 Feb 2020 19:45:36 +0000 (19:45 +0000)
While it is true that [e]poll() only needs POLLOUT
and POLLERR/POLLHUP are added implicitly.
For tevent we need TEVENT_FD_READ in order to see POLLERR/POLLHUP.

The socket becomes only readable when we hit an error.
Waiting for TEVENT_FD_WRITE is needed for getting success,
while TEVENT_FD_READ is required to get failures.

This matches what we have in tstream_bsd_connect_send().

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
lib/async_req/async_sock.c

index 0a8a333f4f34152dedb6f3d423be3f4c3135144b..d0cb06b0638258030e2e3791acb79e263467fd5b 100644 (file)
@@ -147,7 +147,14 @@ struct tevent_req *async_connect_send(
                return tevent_req_post(req, ev);
        }
 
-       state->fde = tevent_add_fd(ev, state, fd, TEVENT_FD_WRITE,
+       /*
+        * Note for historic reasons TEVENT_FD_WRITE is not enough
+        * to get notified for POLLERR or EPOLLHUP even if they
+        * come together with POLLOUT. That means we need to
+        * use TEVENT_FD_READ in addition until we have
+        * TEVENT_FD_ERROR.
+        */
+       state->fde = tevent_add_fd(ev, state, fd, TEVENT_FD_READ|TEVENT_FD_WRITE,
                                   async_connect_connected, req);
        if (state->fde == NULL) {
                tevent_req_error(req, ENOMEM);