Multiple HAProxy Process During HAProxy Reload

We are reloading HAProxy by the following command in our program (doing exec in Go):
haproxy -f /etc/haproxy/haproxy.cfg -p /var/run/haproxy.pid -x /var/run/haproxy.sock -sf <pidlist>

So inside the container, we inspected the reload. It is showing that there are 2 haproxy process running - the old process takes some time to close. Although there aren’t supposed to be any active sessions that can hold it.

  726 root      0:00 haproxy -f /etc/haproxy/haproxy.cfg -p /var/run/haproxy.pid -x /var/run/haproxy.sock -sf 723                                                                                                 
  750 root      0:00 haproxy -f /etc/haproxy/haproxy.cfg -p /var/run/haproxy.pid -x /var/run/haproxy.sock -sf 745                                                                                                 

A crucial details here - this is ps aux output after 2 reload - one immediately after another (inside kubernetes cluster - scaling down/up). So 726 is original process, 745 is pid after first reload and 750 is pid after second reload. Second process isn’t showed here, because after second reload 745 closes almost immediately, but the original process 726 is still ongoing. (closes after about 20s).

Does it usually take so long (around 20 s) or are we using the parameters wrong?
Also, is it possible in any case that old haproxy process never closes using this command?

Haproxy may never quit the old process because of bugs or active connections. You can use hard-stop-after to limit the time for this.

Those 20 seconds are probably spend with sockets. strace -tt the PID to make sure.

You probably want to use a recent stable release and use the worker-master mode (-W), to benefit from latest enhancements in process management. This will add a dedicated master process which will handle everything.