Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
syscall: Go can leak a forked process if main thread exits before spawn finished #33565
Please answer these questions before submitting your issue. Thanks!
What did you do?
If I spawn a process in a goroutine, and exit the main thread before the spawn is finished, I am sometimes left with a fork of my original process that does not go away. The fork does not respond to SIGTERM, and sometimes consumes 100% CPU.
What did you expect to see?
If the main thread exits Go should not leave behind a forked process.
What did you see instead?
A forked process, sometimes using 100% CPU
Does this issue reproduce with the latest release (go1.12.7)?
My guess is that when doing a fork+exec, after the fork, the child wants to "communicate" with the parent; perhaps by reading or writing to a pipe. If the parent is gone the child should exit and do nothing. But it appears that with the "right" timing, the child can get stuck in a loop instead.
changed the title
os/exec: Go can leak a forked process if main thread exits before spawn finished
Aug 9, 2019
There are some lldb stack traces that might help here: https://gitlab.com/gitlab-org/gitaly/issues/1850#note_205304016
Can't reproduce on linux.
I don't believe that is necessarily correct. If a parent exits, the child becomes a zombie and attaches to PID 1. I understand this issue is about cleaning up the child before the spawn has happened completely.
@randall77 for macOS.