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
sort: go 1.6 panic: runtime error: index out of range #14377
Comments
Can you show us a complete program that reproduces the problem? |
Or at least the complete Less function. (Does Go now require Less to be a strict weak ordering like the STL in C++?) |
On golang-nuts @stevenh mentioned that the program has a data race. |
@cespare, thanks. Indeed, from golang-nuts:
No "howevers". Data race = no promises. |
Here's the full version of Less. func (ba Sorter) Less(i, j int) bool {
} -race identified that LastUsed is racey, but it didn't race on the sort On 18/02/2016 04:21, Brad Fitzpatrick wrote:
|
Feel free to re-open this bug if you have a complete stand-alone race-free repro. But if there's a bug, somebody else will hit it. Everybody uses sort. The fact that we haven't seen it already suggests it is due to your race. |
We had a similar issue with one of our sorts where comparison was not deterministic (we used random as a tiebreaker). It makes sense that it should be, but it might be a good idea to either document it or produce a more explicit error message. Example that "works" in go 1.5 but crashes in 1.6:
|
@hamaxx, thanks! I can confirm:
|
I didn't look too deeply into it, but I think it might be pretty easy to just fix the issue for the next release:
|
I didn't thought about "random tie breaker" when i've changed comparison to inequality check. While I think "random tie breaker" is not a good thing, it is sometimes useful. So patch should be applied. Had someone sent already change for review? |
@funny-falcon, no, there is no patch yet. It would be referenced here automatically if so. Want to send one? |
@hamaxx wrote it already in his comments (both test case and fix), so if he wants to make a patch, i will not cross his way. |
Aside: I would recommend against the "random tie breaker" method. While I do think the index out of bound panic should be fixed, I don't think sort.Sort makes any guarantees about the output ordering when Less is not a deterministic total ordering function. (And the random tie breaker method violates both determinism and total ordering.) |
@mdempsky if you are team leader, you shall not allow "random tie breaker" to be merged into master. "rtb" is really a hack. But if you makes personal project, then it is "quick and dirty" way to "sort by priority and get some random elements from min/max/mean priority". Is Go only for good teams, or for "teenagers" also? |
@funny-falcon, or @hamaxx, please send a CL. Code in comments isn't enough. Thanks. |
Sure, I can send a CL. |
@hamaxx, thanks! |
It's not clear to me that defending against inconsistent Less functions is required of sort.Sort. Therefore it's not clear to me that this needs to go into a point release. |
Some one points to Go1x compatibility claim: program were working before Go1.6 and now it fails. I believe it is my fault: when I changed condition I had an image of stable Less in my mind, and I forgot about "random tie breaker". "rtb" is really useful in some "quick&dirty" programs. |
CL https://golang.org/cl/19823 mentions this issue. |
CL https://golang.org/cl/22039 mentions this issue. |
Fixes #14377 Change-Id: I130a6e1b8bc827db44efd0a74e759b894ecc4977 Reviewed-on: https://go-review.googlesource.com/19823 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-on: https://go-review.googlesource.com/22039
It looks like the recent sort improvements, released in go 1.6 result in a runtime panic: index out of range
After updating to go 1.6 a simple sort that was working fine in 1.5.3 now causes a panic: runtime error: index out of range.
I added some debugging to try can catch it in the act and it seems like go 1.6's sort may be broken.
Output:
I should never see that second LEN call as it means that sort called Less with i or j >= Len().
Code snippet
Reverting: e71d640 makes the problem go away.
The text was updated successfully, but these errors were encountered: