forked from TrueCloudLab/distribution
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 (
|
||||
totalBackoff time.Duration
|
||||
count int
|
||||
retries int
|
||||
)
|
||||
|
||||
|
@ -60,9 +61,10 @@ func Generate() (u UUID) {
|
|||
time.Sleep(b)
|
||||
totalBackoff += b
|
||||
|
||||
_, err := io.ReadFull(rand.Reader, u[:])
|
||||
n, err := io.ReadFull(rand.Reader, u[count:])
|
||||
if err != nil {
|
||||
if retryOnError(err) && retries < maxretries {
|
||||
count += n
|
||||
retries++
|
||||
Loggerf("error generating version 4 uuid, retrying: %v", err)
|
||||
continue
|
||||
|
|
Loading…
Reference in a new issue