Reduce consumption of entropy source

The UUID generation retries multiple times to read a full UUID, but
preserves any bytes of entropy he successfully managed to read between
retries.

Signed-off-by: Arnaud Porterie <arnaud.porterie@docker.com>
This commit is contained in:
Arnaud Porterie 2015-07-28 10:01:54 -07:00
parent 0355c3026c
commit c4d69174ee
1 changed files with 3 additions and 1 deletions

View File

@ -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