Hi Willy,

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.

--
Christopher Faulet
>From a9a69d0a5cc9fcc7be84966fc5861cc17400a849 Mon Sep 17 00:00:00 2001
From: Christopher Faulet <cfau...@haproxy.com>
Date: Mon, 18 Dec 2017 14:36:44 +0100
Subject: [PATCH] BUG/MEDIUM: mworker: Close log socket during a reload

A log socket (UPD 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.

This patch must be backported in 1.8.
---
 include/proto/log.h |  3 ++-
 src/haproxy.c       |  1 +
 src/log.c           | 16 ++++++++++++++--
 3 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/include/proto/log.h b/include/proto/log.h
index c92217c9d..a79dac610 100644
--- a/include/proto/log.h
+++ b/include/proto/log.h
@@ -51,9 +51,10 @@ extern THREAD_LOCAL char *logline_rfc5424;
 
 
 /*
- * Initializes some log data.
+ * (de)Initializes some log data.
  */
 void init_log();
+void deinit_log();
 
 
 /* Initialize/Deinitialize log buffers used for syslog messages */
diff --git a/src/haproxy.c b/src/haproxy.c
index ffd7ea05e..87569ca01 100644
--- a/src/haproxy.c
+++ b/src/haproxy.c
@@ -2783,6 +2783,7 @@ int main(int argc, char **argv)
 		if (proc == global.nbproc) {
 			if (global.mode & MODE_MWORKER) {
 				mworker_cleanlisteners();
+				deinit_log();
 				deinit_pollers();
 
 				if ((!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE)) &&
diff --git a/src/log.c b/src/log.c
index 0b8467f33..3239e7ed6 100644
--- a/src/log.c
+++ b/src/log.c
@@ -232,6 +232,9 @@ THREAD_LOCAL char *logline_rfc5424 = NULL;
  * retrieve on the CLI. */
 static THREAD_LOCAL char *startup_logs = NULL;
 
+static THREAD_LOCAL int logfdunix = -1;	/* syslog to AF_UNIX socket */
+static THREAD_LOCAL int logfdinet = -1;	/* syslog to AF_INET socket */
+
 struct logformat_var_args {
 	char *name;
 	int mask;
@@ -1099,8 +1102,6 @@ void __send_log(struct proxy *p, int level, char *message, size_t size, char *sd
 		//.msg_iov = iovec,
 		.msg_iovlen = NB_MSG_IOVEC_ELEMENTS
 	};
-	static THREAD_LOCAL int logfdunix = -1;	/* syslog to AF_UNIX socket */
-	static THREAD_LOCAL int logfdinet = -1;	/* syslog to AF_INET socket */
 	static THREAD_LOCAL char *dataptr = NULL;
 	int fac_level;
 	struct list *logsrvs = NULL;
@@ -1344,6 +1345,16 @@ void init_log()
 	}
 }
 
+void deinit_log()
+{
+	if (logfdunix >= 0)
+		close(logfdunix);
+	if (logfdinet >= 0)
+		close(logfdinet);
+	logfdunix = -1;
+	logfdinet = -1;
+}
+
 static int init_log_buffers_per_thread()
 {
 	return init_log_buffers();
@@ -2420,6 +2431,7 @@ static void __log_init(void)
 {
 	hap_register_per_thread_init(init_log_buffers_per_thread);
 	hap_register_per_thread_deinit(deinit_log_buffers_per_thread);
+	hap_register_post_deinit(deinit_log);
 	cli_register_kw(&cli_kws);
 }
 /*
-- 
2.13.6

Reply via email to