diff mbox series

[ovs-dev,v3] daemon-unix: Fix file descriptor leak when monitor restarts child

Message ID 20220930010928.2419-1-lifengqi@inspur.com
State Accepted
Commit 691c5a5defc4f67b0932c71d80a517c46c711859
Headers show
Series [ovs-dev,v3] daemon-unix: Fix file descriptor leak when monitor restarts child | expand

Checks

Context Check Description
ovsrobot/apply-robot success apply and check: success
ovsrobot/github-robot-_Build_and_Test success github build: passed

Commit Message

Fengqi Li Sept. 30, 2022, 1:09 a.m. UTC
When segmentation fault occured in ovn-northd, monitor will try to
restart the ovn-northd daemon process every 10s.
Assume the following scenarios: There is a segmentation fault and
the ovn-northd daemon process doen not restart properly everytime.
New fds are created each time the ovn-northd daemon process is
restarted by the monitor process, but old fds(fd[1]) ownered by
the monitor process was not closed properly. One pipe leak for
each restart of the ovn-northd daemon process. After a long time
the OS's pipe was exhausted.
Fixes: e2ed6fbeb18c ("fatal-signal: Catch SIGSEGV and print backtrace.")

Signed-off-by: Fengqi Li <lifengqi@inspur.com>
---
 lib/daemon-unix.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Ilya Maximets Oct. 7, 2022, 8:49 a.m. UTC | #1
On 9/30/22 03:09, Fengqi Li wrote:
> When segmentation fault occured in ovn-northd, monitor will try to
> restart the ovn-northd daemon process every 10s.
> Assume the following scenarios: There is a segmentation fault and
> the ovn-northd daemon process doen not restart properly everytime.
> New fds are created each time the ovn-northd daemon process is
> restarted by the monitor process, but old fds(fd[1]) ownered by
> the monitor process was not closed properly. One pipe leak for
> each restart of the ovn-northd daemon process. After a long time
> the OS's pipe was exhausted.
> Fixes: e2ed6fbeb18c ("fatal-signal: Catch SIGSEGV and print backtrace.")
> 
> Signed-off-by: Fengqi Li <lifengqi@inspur.com>
> ---
>  lib/daemon-unix.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/lib/daemon-unix.c b/lib/daemon-unix.c
> index 52f3d4bc6..1a7ba427d 100644
> --- a/lib/daemon-unix.c
> +++ b/lib/daemon-unix.c
> @@ -396,6 +396,8 @@ monitor_daemon(pid_t daemon_pid)
>                  }
>  
>                  log_received_backtrace(daemonize_fd);
> +                close(daemonize_fd);
> +                daemonize_fd = -1;
>  
>                  /* Throttle restarts to no more than once every 10 seconds. */
>                  if (time(NULL) < last_restart + 10) {

Thanks!  Applied and backported down to 2.13.

Best regards, Ilya Maximets.
diff mbox series

Patch

diff --git a/lib/daemon-unix.c b/lib/daemon-unix.c
index 52f3d4bc6..1a7ba427d 100644
--- a/lib/daemon-unix.c
+++ b/lib/daemon-unix.c
@@ -396,6 +396,8 @@  monitor_daemon(pid_t daemon_pid)
                 }
 
                 log_received_backtrace(daemonize_fd);
+                close(daemonize_fd);
+                daemonize_fd = -1;
 
                 /* Throttle restarts to no more than once every 10 seconds. */
                 if (time(NULL) < last_restart + 10) {