Skip to content

Commit f60fc99

Browse files
committed
lock for keygen
1 parent db713a0 commit f60fc99

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

scouterx/common/util/keygen/keygen.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ var keygen *KeyGen
1313

1414
// A KeyGen is a source of random numbers
1515
type KeyGen struct {
16+
sync.Mutex
1617
random *rand.Rand
1718
}
1819

@@ -29,7 +30,10 @@ func getInstance() *KeyGen {
2930

3031
// Next returns a non-negative pseudo-random 63-bit integer
3132
func Next() int64 {
32-
return keygen.random.Int63()
33+
keygen.Lock()
34+
key := keygen.random.Int63()
35+
keygen.Unlock()
36+
return key
3337
}
3438

3539
func init() {

0 commit comments

Comments
 (0)