jcmoraisjr / haproxy-ingress

HAProxy Ingress
https://haproxy-ingress.github.io
Apache License 2.0
1.04k stars 269 forks source link

Move embedded haproxy process to a distinct pid group #1136

Closed jcmoraisjr closed 3 months ago

jcmoraisjr commented 3 months ago

The embedded haproxy process is being created in the same pid group of the controller, which makes it receive the same signals received by the controller when running under a process supervisor. This makes haproxy be prematurely terminated when the controller is still shutting down.

jcmoraisjr commented 3 months ago

1028

avmnu-sng commented 3 months ago

@jcmoraisjr Don't we need to update haproxy-shutdown.sh to send USR1, it still sends TERM which is hard stop. https://github.com/jcmoraisjr/haproxy-ingress/blob/914b58192a0a76fefc52f46d3a65a608f21ced90/rootfs/haproxy-shutdown.sh#L23 kill -USR1 $pid

Even for the master-worker mode. https://github.com/jcmoraisjr/haproxy-ingress/blob/914b58192a0a76fefc52f46d3a65a608f21ced90/pkg/haproxy/instance.go#L661

jcmoraisjr commented 3 months ago

Hi, in fact this shouldn't make any difference because, when shutdown.sh is called, the controller process is being shutting down as well, dropping all the other process in that same container. So moving from term to usr1 would be a noop to the observer. I understand your concern, and I also think we've already discussed that on another issue, and the point here is that the correct place to configure a long living haproxy connection during rolling updates is not here, but instead making the controller to postpone its own shutdown. Moreover, this script belongs to a way to run haproxy which is being deprecated. master-worker is the new default from v0.15, and it calls haproxy directly without any help of external scripts.

avmnu-sng commented 3 months ago

@jcmoraisjr Yeah, we discussed it earlier. I guess I understand now why USR1 is still a no-op. For example, suppose we have wait-before-shutdown=10s. Then, after 10s, irrespective of USR1 or TERM on HAProxy, the ingress controller exits immediately. It would only work if we wait after triggering the HAProxy shutdown. Even if we move to master-worker, we still need a soft stop on HAProxy, and shouldn't ideally, the controller should exit after HAProxy shutdown completes.

jcmoraisjr commented 3 months ago

I see your point. When running haproxy as a daemon we don't have a good control of the underlying process. In master worker mode we run it in the foreground, this gives us a few more options.

Here is where the process is started, stopped, and asked to be stopped:

https://github.com/jcmoraisjr/haproxy-ingress/blob/a7e4b1f02d91d919feb11d83fe3d48a09dad185d/pkg/haproxy/instance.go#L632-L667

and here is the channel that makes the controller wait until haproxy is gone:

https://github.com/jcmoraisjr/haproxy-ingress/blob/a7e4b1f02d91d919feb11d83fe3d48a09dad185d/pkg/haproxy/instance.go#L402-L423

In this scenario it makes sense to send usr1 because the controller will wait for it. I'll give this a chance, maybe adding as a config option. Tks btw for bringing this scenario again and again =)

avmnu-sng commented 3 months ago

@jcmoraisjr No worries; finally, we are on the same page. For now, with Setpgid: true, running in master-worker mode with a sensible wait-before-shutdown value would take us closer to a soft-stop experience.

Please give the config option approach a shot; it would be helpful. Thanks!