From: Willy Tarreau Date: Fri, 15 Jul 2022 17:15:02 +0000 (+0200) Subject: MEDIUM: proto: stop protocols under thread isolation during soft stop X-Git-Tag: v2.7-dev2~39 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1b927eb3c;p=thirdparty%2Fhaproxy.git MEDIUM: proto: stop protocols under thread isolation during soft stop protocol_stop_now() is called from do_soft_stop_now() running on any thread that received the signal. The problem is that it will call some listener handlers to close the FD, resulting in an fd_delete() being called from the wrong group. That's not clean and we cannot even rely on the thread mask to show up. One interesting long-term approach could be to have kill queues for FDs, and maybe we'll need them in the long run. However that doesn't work well for listeners in this situation. Let's simply isolate ourselves during this instant. We know we'll be alone dealing with the close and that the FD will be instantly deleted since not in use by any other thread. It's not the cleanest solution but it should last long enough without causing trouble. --- diff --git a/src/proxy.c b/src/proxy.c index 7c07321276..e38970106d 100644 --- a/src/proxy.c +++ b/src/proxy.c @@ -2198,9 +2198,14 @@ static void do_soft_stop_now() } } + /* we isolate so that we have a chance of stopping listeners in other groups */ + thread_isolate(); + /* stop all stoppable listeners */ protocol_stop_now(); + thread_release(); + /* signal zero is used to broadcast the "stopping" event */ signal_handler(0); }