cmd/go: incorrect compilation of a specific function results in wasm crashes in Chrome on Android #68156
Labels
GoCommand
cmd/go
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Go version
go version go1.22.4 darwin/arm64
Output of
go env
in your module/workspace:What did you do?
Apologies for the convoluted steps for reproducing. I tried for several hours to get a more reproducible example, but I could not. Somehow there is some deleterious interaction between these various components, and removing any one of them stops the issue. This may seem like an issue to do with one of these third party libraries, but as you will see, this behavior seems to almost certainly be an issue with the compiler or Chromium itself.
I made a
go.work
workspace containing local clones of the main/master branches of Cogent Core (https://github.com/cogentcore/core) and goldmark (https://github.com/yuin/goldmark). Then, I went to Cogent Core (cd core
) and installed the Cogent Core tool (go install ./cmd/core
). Then, I went to the basic example in Cogent Core (cd examples/basic
) and ran the program for web usingcore run web
.core run web
is a command that runsgo build
usingGOOS=js GOARCH=wasm
under the hood. Then, I went to port 8080 of my computer's local IP address (http:https://192.168.1.x:8080
; you can runifconfig
to get yours) in Google Chrome on an Android phone (mine is a Pixel 7 Pro running Android 14 with Chrome 126.0.6478.72). I observed that everything worked as expected.Then, I changed the following line in
basic.go
inexamples/basic
fromto
Then, I repeated the
core run web
step from above, opened a new tab on the Android phone, and went to the same URL again. After waiting for some amount of time (no more than a minute), I observed the issue described below.What did you see happen?
After following all of the steps above, the browser tab reliably turns from correctly rendering the app to displaying an
Aw, Snap!
error screen (as in https://support.google.com/chrome/answer/95669). Nothing is printed to the console and no further information about a specific error is given.What did you expect to see?
I expected to see the browser tab continue to correctly render the app.
After several hours of debugging, I have determined that the cause of the issue can be narrowed down to a single function declared in goldmark:
util.ReadWhile
. When I change the body of this function to just bepanic("ReadWhile")
, not only does the issue described above cease to happen, the app does not panic. This means that we are actually not even calling this function in the first place, yet somehow its contents are causing bizarre app crashes. I tried various different variations of this function:println("ReadWhile")
with areturn 0, false
afterward results in no crashing and no print statement, whereas the same but withfmt.Println("ReadWhile")
results in crashing just like the original body of the function. Several variations on the argument and loop structure of the function have not produced any changes in the crashing behavior; you basically have to remove the entire body of the function for it to stop crashing. Changing the name toSomethingElse
also does not stop the crashing. I also tried moving thisReadWhile
function elsewhere, but somehow I could not replicate the crash without it being in the same place in goldmark.The fact that the innocuous contents of a function that is never called lead the program to randomly crash without any further details suggests that this is not a coding error on the part of a third party library but rather some issue with the way that the compiler is building wasm files, or the way that Chromium on Android is handling them. Cogent Core has its own custom
wasm_exec.js
file, but I verified that the issue still occurs with the standard version contained inmisc
.I have only been able to reproduce this issue in Chrome on Android and other Chromium browsers on Android such as Kiwi Browser. It does not occur in Firefox on Android, Safari on iOS, or Chrome on macOS, Ubuntu, or Windows.
The text was updated successfully, but these errors were encountered: