You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
2.4 KiB

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