Skip to content

Commit 9c2ac6f

Browse files
authored
rpc: remove silly use of ReadVarint in subscription ID generator (#21391)
Found by @protolambda
1 parent a00dc50 commit 9c2ac6f

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

rpc/subscription.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package rpc
1818

1919
import (
20-
"bufio"
2120
"container/list"
2221
"context"
2322
crand "crypto/rand"
@@ -51,10 +50,14 @@ func NewID() ID {
5150

5251
// randomIDGenerator returns a function generates a random IDs.
5352
func randomIDGenerator() func() ID {
54-
seed, err := binary.ReadVarint(bufio.NewReader(crand.Reader))
55-
if err != nil {
53+
var buf = make([]byte, 8)
54+
var seed int64
55+
if _, err := crand.Read(buf); err == nil {
56+
seed = int64(binary.BigEndian.Uint64(buf))
57+
} else {
5658
seed = int64(time.Now().Nanosecond())
5759
}
60+
5861
var (
5962
mu sync.Mutex
6063
rng = rand.New(rand.NewSource(seed))

0 commit comments

Comments
 (0)