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
x/exp/shiny: memory corruption on windows #48086
Comments
lockOSThread locks the goroutine to the current OS thread, which is not necessarily the main thread. So the lockOSThread around syscall.Syscall does not guarantee the syscall is made on the main thread. |
cc @nigeltao |
I really don't know much about Windows programming generally and SendMessage specifically, so I'll leave this for others. |
I built your program using current tip of both main Go repo and What I am doing wrong? Thank you. Alex |
There's a comment at the top of the code that shows a script to restart the program in a loop continuously until it errors out. It was by using such a script that it took around a minute to trigger the bug. In that comment I gave a bash script for running the program in a loop (I'm using cygwin). The batch file version would be:
Today, on two different computers (both Windows 10 version 19042.1165), after compiling with gotip, the fastest it printed the message was 2s, the slowest was 5m50s, the average was around 3m. Several times slower than when I tested it just before originally posting this bug, for whatever reason. ( Edit: I had a paragraph here about a version of the repro code that triggers the bug faster, but I just discovered that while on one computer, it triggers the bug reliably within 10 seconds, on a different computer it's not triggered faster at all. I'll leave it here for completeness, but it may or may not be useful to you: http://theinternetftw.com/code/shinyrepro2.zip ) Cheers. |
@theinternetftw thank you very much for your instructions. Indeed I can reproduce your problem. Unfortunately I don't know what the problem is, so leaving it for others to decide what to do here. Alex |
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?
https://gist.github.com/theinternetftw/95151dd990fe955644275e13993ef69e
What did you expect to see?
To never see the "memory corruption!" Println
What did you see instead?
The "memory corruption" Println appears quite regularly. (As did memory corruption of large slices in my actual program)
Discussion
I have stopped this behavior by having shiny not call SendMessage outside of the main os thread.
I stopped major investigation once I fixed it for myself and didn't see any recurrence, but a few thoughts on what might be causing it that may help:
Perhaps somehow waiting for SendMessage when it involves a window in particular is what causes the corruption, or when SendMessage takes some time to return a result.
It might be relevant that the os thread lock is permanently grabbed by the main driver thread, but lockOSThread is nonetheless called later when the syscall.Syscall family of functions is used.
The text was updated successfully, but these errors were encountered: