-
Notifications
You must be signed in to change notification settings - Fork 18k
runtime, syscall: syscall.GetMessage hangs indefinitely after calling runtime.GC() #34301
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
Just some more information. I implemented my own Hotkeys without syscall using cgo. The same thing happens. My cgo code implementationpackage main
/*
#include <windows.h>
#include <stdio.h>
void registerHotKey(int id, UINT modifiers, UINT key) {
if (RegisterHotKey(NULL, id, modifiers, key)) //0x42 is 'b' 0x4000 is MOD_NOREPEAT
{
wprintf(L"Hotkey 'alt+b' registered, using MOD_NOREPEAT flag\n");
} else {
wprintf(L"It failed\n");
}
}
MSG msg;
int getMessageHotKey() {
BOOL rt;
//rt = PeekMessageA(&msg, NULL, 0, 0, 0); //this works as well
rt = GetMessageA(&msg, NULL, 0, 0);
if (rt == -1 || rt == 0) {
return rt;
} else {
if (msg.message == WM_HOTKEY) {
return msg.wParam;
}
}
}
*/
import "C"
import (
"fmt"
"runtime"
)
func main() {
C.registerHotKey(1, 0x0001, 0x42)
count := 0
for {
count++
id := C.getMessageHotKey()
if id == 1 {
fmt.Println("alt+b pressed")
}
fmt.Println("Alloc %v", getAlloc())
runtime.GC()
}
}
func getAlloc() uint64 {
var m runtime.MemStats
runtime.ReadMemStats(&m)
return m.Alloc
} |
Thank you for filing this bug @Ragnoroct and welcome to the Go project! I shall kindly ping some Windows, CGO and runtime experts: @alexbrainman @ianlancetaylor @aclements. |
Thanks :) Just to add some more info too. I tried adding TranslateMessage(&msg);
DispatchMessage(&msg); right after GetMessage to my cgo example and that also didn't work. I thought that possible https://docs.microsoft.com/en-us/windows/win32/winmsg/about-messages-and-message-queues#message-deadlocks might be a clue as to what is going on but I couldn't really figure out the how |
@Ragnoroct May I kindly ask you something? Do you really need to run |
No, I don't need to run It "probably" wouldn't be a problem but what if the GC does need to run. The application will just break without any chance of recovery or restarting. |
Where I got a hunch that syscall's GetMessage on windows has a memory leak is from the second comment on this SO answer https://stackoverflow.com/a/38954281/10111548 |
@Ragnoroct I see your point there, thank you for explaining to me. However, I feel strange for the |
I don't know what is going on here. Can anybody else recreate the problem? |
I think this is not a bug of Go. |
@mattn That fixes it. When I Adding I'll mark it as closed now. Thanks for the help. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
It is the latest release
What operating system and processor architecture are you using (
go env
)?Windows 10
Version 10.0.17763 Build 17763
go env
OutputWhat did you do?
Use syscall to register a windows hotkey and then use GetMessage to get messages for the hotkey. After each loop run runetime.GC(). This will free GetMessage and it won't get any more messages. It just hangs indefinitely.
Run this program and press alt+b to trigger the hotkey
What did you expect to see?
I expected pGetMessage to return the next time I pressed alt+b
What did you see instead?
After the first successful pGetMessage and then runtime.GC, pGetMessage hangs/freezes on that line.
The text was updated successfully, but these errors were encountered: