mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
etcdhttp: never return 0 from genId
This commit is contained in:
parent
56c6fab53c
commit
6d7acc6b1e
@ -86,12 +86,18 @@ func (h Handler) serveRaft(ctx context.Context, w http.ResponseWriter, r *http.R
|
||||
}
|
||||
}
|
||||
|
||||
// genId generates an random id that is: n < 0 < n.
|
||||
func genId() int64 {
|
||||
b := make([]byte, 8)
|
||||
if _, err := io.ReadFull(rand.Reader, b); err != nil {
|
||||
panic(err) // really bad stuff happened
|
||||
for {
|
||||
b := make([]byte, 8)
|
||||
if _, err := io.ReadFull(rand.Reader, b); err != nil {
|
||||
panic(err) // really bad stuff happened
|
||||
}
|
||||
n := int64(binary.BigEndian.Uint64(b))
|
||||
if n != 0 {
|
||||
return n
|
||||
}
|
||||
}
|
||||
return int64(binary.BigEndian.Uint64(b))
|
||||
}
|
||||
|
||||
func parseRequest(r *http.Request) (etcdserverpb.Request, error) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user