runtime: Go program built as a DLL kills the application with exit code 2 due to signal handler #35965
Labels
FrozenDueToAge
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
OS-Windows
Milestone
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
We use go to build a windows DLL that we later load in various environments (Python, C#, Node.js).
Our issue is caused by the behaviour of the signal handler
ctrlhandler1
insrc/runtime/os_windows.go
. If the signal is not handled in go environment the handler callsexit(2)
killing the entire application. That may be desired when go program is an application. However, in the case of DLL the behavior prevents other handlers registered throughSetConsoleCtrlHandler
to run (e.g. the one registered by Python) killing the entire application instead (with exit code2
). Registering the signal handler in go is not an option as this prevents other handlers to run completely by returningtrue
(signal handled) inctrlhandler1
.Here is an example of a go program build as a DLL and a Python script that loads the DLL. The
handler
in the Python script never gets called due to go killing the application. We have the same issue with all other environments (like Node.js). We have also prepared a little zip with reproduction downloadable here: go_repro.zipIt is worth noting that we don't have the same issue under Linux or Mac OS.
We, unfortunately, cannot come up with any workaround like changing handlers order or removing go's handler completely. Our only option as of now is to build the DLL with a modified go compiler.
We appreciate suggestions to work around this as much as a possible change of the behavior. Possibly the runtime would not
exit(2)
when building as a DLL if that is possible and viable.Thank you for examining our issue.
What did you expect to see?
What did you see instead?
The text was updated successfully, but these errors were encountered: