-
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
runtime: deadlock when calling a windows DLL with a callback #55015
Comments
Just to add a bit more context. The PR that replaces Apart from that, both applications that I added as example should behave exactly the same. |
I agree that this is related to #6751. We look for deadlocks in checkdead, which claims to account for callbacks from This needs a closer look. |
Hi! This is a friendly ping to check the status of this issue. We are really looking forward to get rid of CGO in our project and this is blocking us from doing it. We found out that adding a goroutine that stays alive during the execution of our callbacks fixes the issue: go func() {
<-time.After(24 * 365 * time.Hour)
}() But to be honest I would like to avoid using that as a workaround. |
Signed-off-by: deadprogram <[email protected]>
Signed-off-by: deadprogram <[email protected]>
Signed-off-by: deadprogram <[email protected]>
There's an error in the Go runtime that causes a deadlock error whenever we are waiting for a delegate callback to happen. This is because Go is not able to detect that we are going to receive a syscall in the future. See this for more information: golang/go#55015
There's an error in the Go runtime that causes a deadlock error whenever we are waiting for a delegate callback to happen. This is because Go is not able to detect that we are going to receive a syscall in the future. See this for more information: golang/go#55015
There is an alternative solution?
Do I need a go routine only until the callback was called once? |
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?
I'm working on a library to call WinRT APIs on Windows, and I was trying to remove the need for CGO by replacing all calls to
malloc
andfree
byHeapAlloc
andHeapFree
(kernel32.dll
).Some APIs require callbacks to pass information back to the caller, and we were using CGO to allocate memory into the heap, and have the callbacks defined in C. So we may wait indefinitely for the callback to be called
This was working fine with CGO+
malloc
. But as soon as we switched toHeapAlloc
without CGO, we are getting afatal error: all goroutines are asleep - deadlock!
error.The problem seems related to #6751, but for some reason it is still failing for me.
This is a bit hard to reproduce, so I created this repo that includes two applications: https://github.com/jagobagascon/go-deadlock-example
They both scan for BLE devices (so you need bluetooth for it to work, if this is a problem I could probably find some other API wher it fails).
But one of them depends on the old
malloc
+CGO based WinRT API, and the other is pointing to a branch that calls theHeapAlloc
function instead (no CGO required).What did you expect to see?
Changing
malloc
forHeapAlloc
should not cause a deadlock.What did you see instead?
The same code fails when using
HeapAlloc
instead ofmalloc
.Related issues
Maybe #6751
The text was updated successfully, but these errors were encountered: