mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-09-23 14:51:27 +02:00
MEDIUM: checks: avoid accumulating TIME_WAITs during checks
Some checks which do not induce a close from the server accumulate local TIME_WAIT sockets because they're cleanly shut down. Typically TCP probes cause this. This is very problematic when there are many servers, when the checks are fast or when local source ports are rare. So now we'll disable lingering on the socket instead of sending a shutdown. Before doing this we try to drain any possibly pending data. That way we avoid sending an RST when the server has closed first. This change means that some servers will see more RSTs, but this is needed to avoid local source port starvation.
This commit is contained in:
parent
ef8a719f70
commit
fd29cc537b
13
src/checks.c
13
src/checks.c
@ -1157,11 +1157,18 @@ static void event_srv_chk_r(struct connection *conn)
|
||||
*s->check.bi->data = '\0';
|
||||
s->check.bi->i = 0;
|
||||
|
||||
/* Close the connection... */
|
||||
/* Close the connection... We absolutely want to perform a hard close
|
||||
* and reset the connection if some data are pending, otherwise we end
|
||||
* up with many TIME_WAITs and eat all the source port range quickly.
|
||||
* To avoid sending RSTs all the time, we first try to drain pending
|
||||
* data.
|
||||
*/
|
||||
if (conn->xprt && conn->xprt->shutw)
|
||||
conn->xprt->shutw(conn, 0);
|
||||
if (!(conn->flags & (CO_FL_WAIT_L4_CONN|CO_FL_SOCK_WR_SH)))
|
||||
shutdown(conn->t.sock.fd, SHUT_RDWR);
|
||||
if (!(conn->flags & CO_FL_WAIT_RD))
|
||||
recv(conn->t.sock.fd, trash.str, trash.size, MSG_NOSIGNAL|MSG_DONTWAIT);
|
||||
setsockopt(conn->t.sock.fd, SOL_SOCKET, SO_LINGER,
|
||||
(struct linger *) &nolinger, sizeof(struct linger));
|
||||
__conn_data_stop_both(conn);
|
||||
task_wakeup(t, TASK_WOKEN_IO);
|
||||
return;
|
||||
|
Loading…
x
Reference in New Issue
Block a user