-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
reflect: Select panics if array length greater than 1<<16 #37350
Comments
reflect.Select will likely be extremely expensive if you're passing 65k cases; it will have to sort the 65k channels, acquire 65k locks, register itself on 65k independent wait queues, etc. It seems like a good thing that it panics at that scale? (Maybe it should panic even sooner at some lower value) |
It's a fair point, I figured we were abusing the API. I'm pretty O-K if the solution to this ends up being to just update the function doc, it's not clear right now without looking at the code (i.e. no warning) that there's an upper limit to how many you can pass in. Our work around for this was pretty much to shard out the work across threads instead of using a mega thread with all the select cases. WDYT? |
If we do decide to panic on cases like this it for sure should not be a panic that just says "slice bounds out of range". Personally I'm inclined to think that we should just support it. Yes, the performance will be bad. But relatively arbitrary limitations are bad in a different way. If the limit were billions I would feel differently. Thousands of cases doesn't seem inherently absurd. |
If we want to bump up the Not a big deal, but wanted to make sure it's clear that |
Ah, thanks, I hadn't noticed that. Given that I'm OK with the restriction, and I just think that we need 1) documentation; 2) a better panic message. |
Agree, happy to make the change! |
Change https://golang.org/cl/220583 mentions this issue: |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes, here is a go playground example
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
We ran into an issue today where if the number of reflect cases in an array exceeds 1<<16, the call to
reflect.Select
panics. The function doc for the select implementation suggests that it's the length of the array that is used to recreate the pointer to the array, determined by a passed in variablencases
.In fact, that doesn't appear to be true:
The text was updated successfully, but these errors were encountered: