]> git.ipfire.org Git - thirdparty/haproxy.git/commit
BUG/MEIDUM: mworker: fix fd leak from master to worker
authorValentine Krasnobaeva <vkrasnobaeva@haproxy.com>
Sat, 26 Oct 2024 13:01:54 +0000 (15:01 +0200)
committerValentine Krasnobaeva <vkrasnobaeva@haproxy.com>
Sat, 26 Oct 2024 20:53:24 +0000 (22:53 +0200)
commit4931d1ca5fb8c8b56bddb8a617dbb8e19675e551
tree2e020a3a29a6c5065ae24df769807eecfca22875
parent745a4c5e934929e623e7d76d2b4d0d895f043b25
BUG/MEIDUM: mworker: fix fd leak from master to worker

During re-execution master keeps always opened "reload" sockpair FDs and
shared sockpair ipc_fd[0], the latter is using to transfert listeners sockets
from the previously forked worker to the new one. So, these master's FDs are
inherited in the newly forked worker and must be closed in its context.

"reload" sockpair inherited FDs and shared sockpair FD (ipc_fd[0]) are closed
separately, becase master doesn't recreate "reload" sockpair each time after
its re-exec. It always keeps the same FDs for this "reload" sockpair. So in
worker context it can be closed immediately after the fork.

At contrast, shared sockpair is created each time after reload, when the new
worker will be forked. So, if N previous workers are still exist at this moment,
the new worker will inherit N ipc_fd[0] from master. So, it's more save to
close all these FDs after get_listeners_fd() and bind_listeners() calls.
Otherwise, early closed FDs in the worker context will be immediately bound to
listeners and we could potentially have some bugs.
src/haproxy.c
src/sock.c