-
Notifications
You must be signed in to change notification settings - Fork 18.1k
Goroutines cause deadlocks after fork()
when run in shared library
#15538
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
Comments
This is to be expected. It's almost impossible for multithreaded Go runtime
to handle arbitrary forks.
|
Could you recommend a better practice I could suggest to the maintainers of the parent project which is loading my Go lib? Is it sane to |
You're right: this is a problem. A multi-threaded program can not safely call fork; this is a general rule, not specific to Go. A single-threaded program that dlopen's a Go shared library becomes a multi-threaded program. At that point, it can not call fork. I don't think there is anything we can do about this. I'm going to close this as unfortunate. |
I tested my hypothesis that forking a bunch of processes and then calling I can confirm that each process had a different PID with a common parent. Each call to Is this a red herring or is there something I can do successfully run multiple isolated Go runtimes from a shared parent PID? |
I would expect it to work to call |
Note that if your original program includes Go code apart from the shared library you are using with |
Thanks for confirming. I've raised #15556 to address the issue when |
Is there any way possible to re-initialize the go runtime after a fork? Assuming that |
In general, we ask that people not ask questions on closed bugs. If you want to discuss the issues, please use a mailing list or forum; see https://golang.org/wiki/Questions . Thanks. The problem with |
Uh oh!
There was an error while loading. Please reload this page.
If a shared library is written in Go, loaded using
dlopen
and then forked, Go behavior becomes unstable, often resulting in a deadlock or bad file descriptor error.The
bad file descriptor
error is reproduced in this gist: https://gist.github.com/cavaliercoder/688a3cd7dac20c8edb0c0f6f2851b54dComment out the parent pid's call to
(*f)()
oncbin.c:18
to reproduce the deadlock issue.This issue has been reproduced on Go 1.5 and 1.6 on CentOS 7, Ubuntu 14 and OS X with only x86_64.
Stack trace from a hung process:
The text was updated successfully, but these errors were encountered: