Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proposal: cmd/go/internal/run: Use an exec without fork, or pass signals to child #54868

croepha opened this issue Sep 5, 2022 · 6 comments


Copy link

croepha commented Sep 5, 2022

go run ... doesn't handle kill as one might expect. On at-least Linux, It will leave an orphaned process still running.

There are a lot of cases where I think this would be useful, but using something like kill $! in a shell script would be one

Option 1: Use an exec (without fork) on the built binary so that the parent go run ... pid will be the same as the new built code
Option 2: Pass all signals to child. This wont work for some signals, but might be good enough.

@gopherbot gopherbot added this to the Proposal milestone Sep 5, 2022
@ianlancetaylor ianlancetaylor added the GoCommand cmd/go label Sep 5, 2022
Copy link

CC @bcmills @matloob

Copy link

bcmills commented Sep 6, 2022

On the one hand, if you want fine-grained control over signal propagation you can always use go build and then execute the resulting binary. Moreover, it's usually a bad idea to send SIGKILL to any individual process (compare #50436) — that does tend to orphan any subprocesses, and the use of subprocesses should essentially always be an implementation detail.

On the other hand, it would be nice to preserve the PID presented to the parent when invoking go run anyway. If someone wants to do the work to make this happen (along with good integration tests for it), I think we could reasonably make the time to review the changes.

Copy link

bcmills commented Sep 8, 2022

Compare #40467.

Copy link

zikaeroh commented Sep 8, 2022

Half-related, but if the logic for go run changes, I'd appreciate it changing for the executables too; see #36976.

Copy link

davidmdm commented Oct 1, 2022

I just ran into this issue, trying to send interrupts, sigterm, and sigkill to a child process that was being run via "go run" and no signals were being handled by my program which was unexpected.

Also I would orphan my programs and it wasn't easy to understand why this was happening.

I guess, the point of writing this comment is to give an Anecdote from the point of view of a regular, run of the mill, user.

Copy link

STRRL commented Nov 24, 2022

Recently, I also met this issue when developing vercel serverless function with golang runtime and vercel dev.

vercel dev only kills the go run process, and left /tmp/go-buildxxx/xxx/exec/<binary> as orphan, but it still keeps all the resources like opened files and database connections.


I think maybe it's better to patch on vercel side to bypass this situation. 🙈

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Status: Incoming

No branches or pull requests

7 participants