From: Willy Tarreau Date: Thu, 5 Sep 2019 15:38:40 +0000 (+0200) Subject: BUG/MINOR: checks: do not uselessly poll for reads before the connection is up X-Git-Tag: v2.1-dev2~105 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c594039225;p=thirdparty%2Fhaproxy.git BUG/MINOR: checks: do not uselessly poll for reads before the connection is up It's pointless to start to perform a recv() call on a connection that is not yet established. The only purpose used to be to subscribe but that causes many extra syscalls when we know we can do it later. This patch only attempts a read if the connection is established or if there is no write planed, since we want to be certain to be called. And in wake_srv_chk() we continue to attempt to read if the reader was not subscribed, so as to perform the first read attempt. In case a first result is provided, __event_srv_chk_r() will not do anything anyway so this is totally harmless in this case. This fix requires that commit "BUG/MINOR: checks: make __event_chk_srv_r() report success before closing" is applied before, otherwise it will break some checks (notably SSL) by doing them again after the connection is shut down. This completes the fixes on the checks described in issue #253 by roughly cutting the number of syscalls in half. It must be backported to 2.0. --- diff --git a/src/checks.c b/src/checks.c index 1268cda5ee..e5dfdd73c8 100644 --- a/src/checks.c +++ b/src/checks.c @@ -1447,8 +1447,12 @@ static int wake_srv_chk(struct conn_stream *cs) ret = tcpcheck_main(check); cs = check->cs; conn = cs->conn; - } else if (!(check->wait_list.events & SUB_RETRY_SEND)) - __event_srv_chk_w(cs); + } else { + if (!(check->wait_list.events & SUB_RETRY_SEND)) + __event_srv_chk_w(cs); + if (!(check->wait_list.events & SUB_RETRY_RECV)) + __event_srv_chk_r(cs); + } if (unlikely(conn->flags & CO_FL_ERROR || cs->flags & CS_FL_ERROR)) { /* We may get error reports bypassing the I/O handlers, typically @@ -2260,7 +2264,9 @@ static struct task *process_chk_conn(struct task *t, void *context, unsigned sho * sending since otherwise we won't be woken up. */ __event_srv_chk_w(cs); - __event_srv_chk_r(cs); + if (!(conn->flags & CO_FL_WAIT_L4_CONN) || + !(check->wait_list.events & SUB_RETRY_SEND)) + __event_srv_chk_r(cs); } task_set_affinity(t, tid_bit);