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/mobile: when a panic happens, a long enough traceback deadlocks the runtime on Android #35590
Comments
cc @eliasnaur, I know you don't maintain it anymore but it would be nice to know if the now built-in support in Go itself would enable to remove this bit in gomobile, or there were some other reason for it to exist? |
AFAICT, the runtime only redirects its own printing (of crashes) to stderr. The gomobile redirect is for all writes to stderr (and stdout), not just the runtime's. One fix is to rewrite the gomobile redirect in C(go). |
Another idea would be to implement a buffered writer and only replace |
Wonder if it's possible to let the gomobile directly send all logs to logd using the code similar to runtime/write_err_android.go. More desirably, would be nice if it allows users to turn it on and off - I found logging from some libraries is too chatty for mobile application use cases. |
As stderr may be written while the world is frozen (e.g. the runtime dumping the traceback of a panic), the redirection of stdout and stderr to Android's logcat cannot be done in Go but in C. This implementation spawns a detached thread which will wait for stdout or stderr to be readable, and when so, read one line at a time and write it to Android's logcat. Fixes golang/go#35590
Proposal patch for this issue: golang/mobile#40 |
Change https://golang.org/cl/212839 mentions this issue: |
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 have an Go application compiled for Android with gomobile. When a panic happens, the runtime prints a traceback and quits. However, when this traceback is long enough, the application freezes and never quits.
Gomobile redirects
stderr
to Android (Android log tag being "GoLog"). When a panic happens, the world is frozen, so:lineLog
does not consume anymore the pipedup
-ed tostderr
;stderr
and blocks untilstderr
is writable;Disabling the gomobile's redirection from
stderr
makes the application crashes "properly".Note that the runtime already redirect logs to Android (with the tag "Go"), so the redirection of
stderr
by gomobile seems redundant to me?To reproduce, you can modify the runtime to
println
lot of lines when a panic is caught, until the runtime freezes.What did you expect to see?
When a panic happens, and the resulting traceback is long enough, I expect the runtime to print the full traceback and quit.
What did you see instead?
When a panic happens, and the resulting traceback is long enough, I see the runtime prints a truncated traceback and freezes.
The text was updated successfully, but these errors were encountered: