-
Notifications
You must be signed in to change notification settings - Fork 929
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
Fix: fix rand.Seed() duplicate concurrent calls #1958
Conversation
@@ -44,6 +44,7 @@ var ( | |||
) | |||
|
|||
func init() { | |||
rand.Seed(randSeed()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rand.Seed only need to initialize once
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I think there should be a sync.Once
to initialize the seed globally. Did dubbo-go have it before?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Each init() is called only once in golang, and I think it is sufficient to ensure that the seed does not change after the program starts running, regardless of the number of times the rand.Seed() is called in the program.
In addition, the imported third-party package may call rand.Seed() even if we only run it once
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, the number of initializations of the rand seed is not a very strict limit. This PR looks good for me. BTW, I am saying that initialize the rand seed globally, instead of initialize that in init()
function of each package, but it doesn't matter now.
Codecov Report
@@ Coverage Diff @@
## 3.0 #1958 +/- ##
==========================================
- Coverage 44.96% 44.35% -0.61%
==========================================
Files 287 283 -4
Lines 17135 17023 -112
==========================================
- Hits 7704 7551 -153
- Misses 8618 8668 +50
+ Partials 813 804 -9
Continue to review full report at Codecov.
|
What this PR does:
Move the rand.Seed() call to init()
Which issue(s) this PR fixes:
Fixes #1957
You should pay attention to items below to ensure your pr passes our ci test
We do not merge pr with ci tests failed