Merge pull request #771 from icecrime/uuid_preserve_random_bytes
Reduce consumption of entropy source
This commit is contained in:
commit
a0f7b3ae3c
1 changed files with 3 additions and 1 deletions
|
@ -49,6 +49,7 @@ func Generate() (u UUID) {
|
||||||
|
|
||||||
var (
|
var (
|
||||||
totalBackoff time.Duration
|
totalBackoff time.Duration
|
||||||
|
count int
|
||||||
retries int
|
retries int
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -60,9 +61,10 @@ func Generate() (u UUID) {
|
||||||
time.Sleep(b)
|
time.Sleep(b)
|
||||||
totalBackoff += b
|
totalBackoff += b
|
||||||
|
|
||||||
_, err := io.ReadFull(rand.Reader, u[:])
|
n, err := io.ReadFull(rand.Reader, u[count:])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if retryOnError(err) && retries < maxretries {
|
if retryOnError(err) && retries < maxretries {
|
||||||
|
count += n
|
||||||
retries++
|
retries++
|
||||||
Loggerf("error generating version 4 uuid, retrying: %v", err)
|
Loggerf("error generating version 4 uuid, retrying: %v", err)
|
||||||
continue
|
continue
|
||||||
|
|
Loading…
Reference in a new issue