Merge pull request #10151 from jefferyto/python-bpo-38243-34155
[feed/packages.git] / net / haproxy / patches / 006-BUG-MEDIUM-checks-make-sure-the-connection-is-ready-before-trying-to-recv.patch
1 commit 489bbd321e46c110ab9d92fb91725870d7c40491
2 Author: Willy Tarreau <w@1wt.eu>
3 Date: Tue Sep 24 10:43:03 2019 +0200
4
5 BUG/MEDIUM: checks: make sure the connection is ready before trying to recv
6
7 As identified in issue #278, the backport of commit c594039225 ("BUG/MINOR:
8 checks: do not uselessly poll for reads before the connection is up")
9 introduced a regression in 2.0 when default checks are enabled (not
10 "option tcp-check"), but it did not affect 2.1.
11
12 What happens is that in 2.0 and earlier we have the fd cache which makes
13 a speculative call to the I/O functions after an attempt to connect, and
14 the __event_srv_chk_r() function was absolutely not designed to be called
15 while a connection attempt is still pending. Thus what happens is that the
16 test for success/failure expects the verdict to be final before waking up
17 the check task, and since the connection is not yet validated, it fails.
18 It will usually work over the loopback depending on scheduling, which is
19 why it doesn't fail in reg tests.
20
21 In 2.1 after the failed connect(), we subscribe to polling and usually come
22 back with a validated connection, so the function is not expected to be
23 called before it completes, except if it happens as a side effect of some
24 spurious wake calls, which should not have any effect on such a check.
25
26 The other check types are not impacted by this issue because they all
27 check for a minimum data length in the buffer, and wait for more data
28 until they are satisfied.
29
30 This patch fixes the issue by explicitly checking that the connection
31 is established before trying to read or to give a verdict. This way the
32 function becomes safe to call regardless of the connection status (even
33 if it's still totally ugly).
34
35 This fix must be backported to 2.0.
36
37 (cherry picked from commit 0f0393fc0d2badc5ea329844691f06ba28827f78)
38 Signed-off-by: Willy Tarreau <w@1wt.eu>
39
40 diff --git a/src/checks.c b/src/checks.c
41 index b088da2e..06f47ad9 100644
42 --- a/src/checks.c
43 +++ b/src/checks.c
44 @@ -875,6 +875,9 @@ static void __event_srv_chk_r(struct conn_stream *cs)
45 }
46 }
47
48 + /* the rest of the code below expects the connection to be ready! */
49 + if (!(conn->flags & CO_FL_CONNECTED) && !done)
50 + goto wait_more_data;
51
52 /* Intermediate or complete response received.
53 * Terminate string in b_head(&check->bi) buffer.