fix: fix crash on selecting queue. #643
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What is the purpose of the change
fix crash on selecting queue.
Brief changelog
https://github.com/golang/go/blob/a7e16abb22f1b249d2691b32a5d20206282898f2/src/math/rand/rand.go#L7-L20
The default Source is safe for concurrent use by multiple goroutines, but Sources created by NewSource are not.
如上所述,math/rand中通过NewSource创建的rand方法不是线程安全的。多协程发送消息时,不加锁的情况下同时select queue会因数组越界导致panic。
panic如下:
panic: runtime error: index out of range [-1]