Hi all,

Please find attached a patch to fix the issue reported by Joshua on the ML
and sjiveson on discourse.
I moved the initialisation of the dns_resolvers() after the fork. I can
confirm now than each process has its own UDP socket to send DNS requests.

Baptiste
From 9c77b0f8e1ecee1a330827e134d0f346582f54f9 Mon Sep 17 00:00:00 2001
From: Baptiste Assmann <bed...@gmail.com>
Date: Mon, 30 Jan 2017 22:22:45 +0100
Subject: [PATCH] BUG/MAJOR: dns: create one client UDP socket per process

DNS resolution at run time was incompatible with multi-process mode
because FDs for UDP client socket were initialized before fork()
happened and were shared by all HAProxy processes. This situation lead
to DNS response packets being received by wrong processes.

Current patch moves the call to dns_init_resolvers after the fork.
As a result, now each HAProxy process owns its own UDP socket to send
DNS requests.
---
 src/haproxy.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/haproxy.c b/src/haproxy.c
index 4ad370d..2e38623 100644
--- a/src/haproxy.c
+++ b/src/haproxy.c
@@ -1175,10 +1175,6 @@ static void init(int argc, char **argv)
 	if (!hlua_post_init())
 		exit(1);
 
-	/* initialize structures for name resolution */
-	if (!dns_init_resolvers())
-		exit(1);
-
 	free(err_msg);
 }
 
@@ -1950,6 +1946,10 @@ int main(int argc, char **argv)
 		fork_poller();
 	}
 
+	/* initialize structures for name resolution */
+	if (!dns_init_resolvers())
+		exit(1);
+
 	protocol_enable_all();
 	/*
 	 * That's it : the central polling loop. Run until we stop.
-- 
2.7.4

Reply via email to