From 048a4230b2774f4dd1ec706af5b675226da1e872 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Wed, 2 Oct 2019 07:56:30 -0700 Subject: [PATCH] lib/async_req: make sure we return errors early from async_connect_send/recv 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 Reviewed-by: Jeremy Allison --- lib/async_req/async_sock.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/async_req/async_sock.c b/lib/async_req/async_sock.c index 0a8a333f4f3..d0cb06b0638 100644 --- a/lib/async_req/async_sock.c +++ b/lib/async_req/async_sock.c @@ -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); -- 2.34.1