[MINOR] prevent the system from sending an RST when closing health-checks

On Sat, 22 Sep 2007, Willy Tarreau wrote:
> On Sun, Sep 23, 2007 at 03:23:38AM +0200, Krzysztof Oledzki wrote:
> > I noticed that with httpchk, haproxy generates TCP RST at end of a check.
> > IMHO, it would be more polite to send FIN to a server, especially that
> > each TCP RST found by a tcpdump makes me concerned that something is
> > wrong, as it is hard to distinguish between a RST from a httpchk and from
> > a normal request, forwarded for a client.
>
> I have also noticed it very recently. In fact, it's never the
> application (here haproxy) which decides to send an RST, it's the
> system. It does so because the server returns data on a terminated
> socket. I guess it's because the health-check code does not read much
> of the response. In fact, we just need to read enough to process common
> responses. If people are dumb enough to check with something like "GET
> /image.iso", they should expect to get an RST after a few kbytes
> instead of reading the whole file!

Right, that was easy. Attached patch changed what you described. Now
haproxy finishes http checks with FIN.
This commit is contained in:
Krzysztof Oledzki 2007-10-11 18:41:08 +02:00 committed by Willy Tarreau
parent 56f1e8b368
commit 6b3f8b4b8f

View File

@ -210,7 +210,6 @@ static int event_srv_chk_w(int fd)
static int event_srv_chk_r(int fd) static int event_srv_chk_r(int fd)
{ {
__label__ out_wakeup; __label__ out_wakeup;
char reply[64];
int len, result; int len, result;
struct task *t = fdtab[fd].owner; struct task *t = fdtab[fd].owner;
struct server *s = t->context; struct server *s = t->context;
@ -230,13 +229,13 @@ static int event_srv_chk_r(int fd)
} }
#ifndef MSG_NOSIGNAL #ifndef MSG_NOSIGNAL
len = recv(fd, reply, sizeof(reply), 0); len = recv(fd, trash, sizeof(trash), 0);
#else #else
/* Warning! Linux returns EAGAIN on SO_ERROR if data are still available /* Warning! Linux returns EAGAIN on SO_ERROR if data are still available
* but the connection was closed on the remote end. Fortunately, recv still * but the connection was closed on the remote end. Fortunately, recv still
* works correctly and we don't need to do the getsockopt() on linux. * works correctly and we don't need to do the getsockopt() on linux.
*/ */
len = recv(fd, reply, sizeof(reply), MSG_NOSIGNAL); len = recv(fd, trash, sizeof(trash), MSG_NOSIGNAL);
#endif #endif
if (unlikely(len < 0 && errno == EAGAIN)) { if (unlikely(len < 0 && errno == EAGAIN)) {
/* we want some polling to happen first */ /* we want some polling to happen first */
@ -245,17 +244,17 @@ static int event_srv_chk_r(int fd)
} }
if ((s->proxy->options & PR_O_HTTP_CHK) && (len >= sizeof("HTTP/1.0 000")) && if ((s->proxy->options & PR_O_HTTP_CHK) && (len >= sizeof("HTTP/1.0 000")) &&
(memcmp(reply, "HTTP/1.", 7) == 0) && (reply[9] == '2' || reply[9] == '3')) { (memcmp(trash, "HTTP/1.", 7) == 0) && (trash[9] == '2' || trash[9] == '3')) {
/* HTTP/1.X 2xx or 3xx */ /* HTTP/1.X 2xx or 3xx */
result = 1; result = 1;
} }
else if ((s->proxy->options & PR_O_SSL3_CHK) && (len >= 5) && else if ((s->proxy->options & PR_O_SSL3_CHK) && (len >= 5) &&
(reply[0] == 0x15 || reply[0] == 0x16)) { (trash[0] == 0x15 || trash[0] == 0x16)) {
/* SSLv3 alert or handshake */ /* SSLv3 alert or handshake */
result = 1; result = 1;
} }
else if ((s->proxy->options & PR_O_SMTP_CHK) && (len >= 3) && else if ((s->proxy->options & PR_O_SMTP_CHK) && (len >= 3) &&
(reply[0] == '2')) /* 2xx (should be 250) */ { (trash[0] == '2')) /* 2xx (should be 250) */ {
result = 1; result = 1;
} }