Skip to content
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: go rand crash #21112

Closed
axet opened this issue Jul 21, 2017 · 5 comments
Closed

x/mobile: go rand crash #21112

axet opened this issue Jul 21, 2017 · 5 comments
Labels
FrozenDueToAge mobile Android, iOS, and x/mobile WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Milestone

Comments

@axet
Copy link

axet commented Jul 21, 2017

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

go version go1.8.3 darwin/amd64

What operating system and processor architecture are you using (go env)?

android

What did you do?

Seems like rand.Perm() has a bug, I'm getting a lot of crashes in my torrent app:

panic: runtime error: index out of range

goroutine 5088 [running]:
math/rand.(*Rand).Perm(0x442005a2a0, 0x3c4, 0x4420c22d20, 0x3c4, 0x4420256398)
    /opt/local/lib/go/src/math/rand/rand.go:198 +0xc0
math/rand.Perm(0x3c4, 0x3c4, 0x0, 0x44206c9a60)
    /opt/local/lib/go/src/math/rand/rand.go:288 +0x30
github.com/anacrolix/torrent.(*Torrent).getConnPieceInclination(0x442077ec80, 0x79f47cb650, 0x4420080618, 0x343)

Seems like in rare conditions, function crashes while calulating 'j := r.Intn(i + 1)' which should be 'j := r.Intn(i)'

@bradfitz
Copy link
Contributor

The code looks fine.

Does it crash on only one device of yours, or multiple Android devices? Which ones?

@bradfitz bradfitz changed the title go rand bug x/mobile: go rand crash Jul 21, 2017
@gopherbot gopherbot added this to the Unreleased milestone Jul 21, 2017
@bradfitz bradfitz added WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. mobile Android, iOS, and x/mobile labels Jul 21, 2017
@axet
Copy link
Author

axet commented Jul 21, 2017

@bradfitz crashes in Go native code not captured by the system. So, it does only my device.

My project is:

https://gitlab.com/axet/android-torrent-client

Device Nexus 9, arm

It is hard to debug, but I can add some debug prints and say which numbers are causing the crash. But seems like 'j' out of index, only possible when 'r.Intn(i) <= i' and it should not crash when it is 0 or -1.

I do not know what to do, but just ignore Perm() calls at all in my app...

@bradfitz
Copy link
Contributor

Nexus 9 uses https://en.wikipedia.org/wiki/Project_Denver and has known problems with certain instruction sequences. Go's compiler generates instruction sequences different from what Nexus 9 was tested with, so we apparently confuse the Project Denver JIT.

See similar bug #19809 and all the bugs referenced from it in other non-Go projects.

Nexus 9 just has a buggy CPU. It only works for Android because that's what was tested on it.

Please try Go 1.9. Go 1.8 didn't include the 9d5987d Nexus 9 workaround. So you might be better off with that. Or maybe not.

In any case, there's little we can do here.

@axet
Copy link
Author

axet commented Jul 21, 2017

Seems works!

@cherrymui
Copy link
Member

@dr2chase has wanted to has the workaround backported to Go 1.8. Here is another case.

@golang golang locked and limited conversation to collaborators Jul 21, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge mobile Android, iOS, and x/mobile WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

4 participants