Le 18/12/2017 à 20:11, Willy TARREAU a écrit :
On Mon, Dec 18, 2017 at 03:00:15PM +0100, Christopher Faulet wrote:
This patch should fix the following bug reported on discourse:
https://discourse.haproxy.org/t/freeze-sockets-in-1-8-1-no-http-2/1912
I reproduced the bug described on discourse and my patch fixes it. But,
I will ask for confirmation to be sure it is the same bug.
Thanks Christopher. However, I don't like much the fact that we're starting
to have to reimplement parts of deinit() for the master process, and we'll
always miss a few parts there.
I think a better and more durable solution would look like the totally
untested code below (at least a cleaner version of it) :
diff --git a/src/log.c b/src/log.c
index 0b8467f..de775af 100644
--- a/src/log.c
+++ b/src/log.c
@@ -1176,6 +1176,7 @@ void __send_log(struct proxy *p, int level, char
*message, size_t size, char *sd
setsockopt(*plogfd, SOL_SOCKET, SO_RCVBUF, &zero,
sizeof(zero));
/* does nothing under Linux, maybe needed for others */
shutdown(*plogfd, SHUT_RD);
+ fcntl(*plogfd, F_SETFD, fcntl(*plogfd, F_GETFD,
FD_CLOEXEC) | FD_CLOEXEC);
}
switch (logsrv->format) {
This way we're certain that the socket will alwyays be closed, regardless
of the fact that we call the deinit() code or not. Additionally, it will
take care of closing all such possible log sockets in the future if the
code is duplicated for whatever reason.
What do you think ?
This is a better way to fix the bug, you're right. Here is the updated
patch. Thanks.
--
Christopher Faulet
>From 95c318c78ec9529c01200198b2e6b43701c142f9 Mon Sep 17 00:00:00 2001
From: Christopher Faulet <[email protected]>
Date: Tue, 19 Dec 2017 10:35:53 +0100
Subject: [PATCH] BUG/MEDIUM: mworker: Set FD_CLOEXEC flag on log fd
A log socket (UDP or UNIX) is opened by the master during its startup, when the
first log message is sent. So, to prevent FD leaks, we must ensure we correctly
close it during a reload. By setting FD_CLOEXEC bit on it, we are sure it will
be automatically closed it during a reload.
This patch must be backported in 1.8.
---
src/log.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/src/log.c b/src/log.c
index 0b8467f33..de775af45 100644
--- a/src/log.c
+++ b/src/log.c
@@ -1176,6 +1176,7 @@ void __send_log(struct proxy *p, int level, char *message, size_t size, char *sd
setsockopt(*plogfd, SOL_SOCKET, SO_RCVBUF, &zero, sizeof(zero));
/* does nothing under Linux, maybe needed for others */
shutdown(*plogfd, SHUT_RD);
+ fcntl(*plogfd, F_SETFD, fcntl(*plogfd, F_GETFD, FD_CLOEXEC) | FD_CLOEXEC);
}
switch (logsrv->format) {
--
2.13.6