-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
Golang Shared library behavior in forked processes #16855
Comments
If you're loading Go code before a fork, all bets are off, no? /cc @ianlancetaylor |
But the process already forked (and leaves Go runtime is an inconsistent
state) and I think dlopen will not reload a DSO if it has already been
loaded (even if by the parent process before fork)
|
As I don't have control over the apache code, I was wondering if there is any way out in this scenario. |
There is no such thing as "reloading a shared library". If your process has already loaded the library, then loading it again (calling I do not know of any way to make this work using shared libraries. |
Yeah, I guess if dlclose() was supported, it would have worked. I could have used the pthread_atfork handlers to do dlclose() and load it again in the child process. |
There are no current plans to make I'm going to close this as infeasible. |
On a side note: should Go shared library register an atfork handler that
terminate the whole program with a nice error message rather that panic
later?
|
A |
go version
)?go1.7 linux/amd64
go env
)?Ubuntu 16.04 LTS X86-64
If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on play.golang.org is best.
Issue #15538 establishes that a process which has loaded a Go shared library (and therefore, instantiated the Go runtime) cannot call fork() and make use of Go code in child processes.
Issue #15556 establishes that if library is loaded after fork(), everything works fine.
Also I understand there is no support for dlclose() for the go shared library.
My use case is w.r.t., using a go shared library as a module in apache web server.
I have written a PKCS#11 shared library using Golang. This library is loaded when apache httpd loads mod_nss.
Following is the apache httpd startup flow ( as observed from the stack trace )
https://play.golang.org/p/_Eaqnne7vt
The code is specific to PKCS#11 library. This is reproducible with any Go shared library which uses net.http package
Since the child process is loading the shared library again, I expected the golang shared library runtime to be in a consistent state.
Golang shared library hangs in net.http package waiting for futex
GDB Output:
#1 0x00007f32795fb263 in runtime.futexsleep (addr=0xc820022108, val=0, ns=-1) at /usr/local/go/src/runtime/os1_linux.go:40
#2 0x00007f32795e0ff8 in runtime.notesleep (n=0xc820022108) at /usr/local/go/src/runtime/lock_futex.go:145
#3 0x00007f32796041a2 in runtime.stoplockedm () at /usr/local/go/src/runtime/proc.go:1685
#4 0x00007f32796052c2 in runtime.schedule () at /usr/local/go/src/runtime/proc.go:2033
#5 0x00007f3279605741 in runtime.park_m (gp=0xc820000600) at /usr/local/go/src/runtime/proc.go:2140
#6 0x00007f327962c9b3 in runtime.mcall () at /usr/local/go/src/runtime/asm_amd64.s:233
#7 0x00007fffd5e52918 in ?? ()
#8 0x00007f327962e49a in runtime.cgocallback () at /usr/local/go/src/runtime/asm_amd64.s:629
#9 0x00007f32795bf494 in _cgoexp_6ce49e0b1287_G_GenerateRandom (a=0x7fffd5e529d0, n=32) from /home/osboxes/goWorkspace/libcryptoki_idps.so
The text was updated successfully, but these errors were encountered: