-
Notifications
You must be signed in to change notification settings - Fork 160
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
nu7hatch/gouuid Duplicate sequentially generated V4 UUIDs #28
Comments
Duplicate sequentially generated V4 UUIDs nu7hatch/gouuid#28
Duplicate sequentially generated V4 UUIDs nu7hatch/gouuid#28
Duplicate sequentially generated V4 UUIDs nu7hatch/gouuid#28
Duplicate sequentially generated V4 UUIDs nu7hatch/gouuid#28
hey @jaytaylor I'm looking at the V4 implementation in I found this issue via cloudfoundry/cf-smoke-tests#13 where I'm cross-posting the same question. Thanks! |
IIRC the satori one returns a _UUID while the nu7hatch one returns a tulle of (_UUID, error). Thus the implementations and critical paths are different in that the satori one promises to never return an error.
|
I am not sure I follow the reasoning here at all. A simplified version of the "offending" code is offered below: package uuid
import "crypto/rand"
type UUID [16]byte
func NewV4() (*UUID, error) {
u = new(UUID)
_, err = rand.Read(u[:])
if err != nil {
return
}
return
} And here is the same code in the satori/go.uuid codebase: package uuid
import "crypto/rand"
type UUID [16]byte
func NewV4() UUID {
u := UUID{}
safeRandom(u[:])
return u
}
func safeRandom(dest []byte) {
if _, err := rand.Read(dest); err != nil {
panic(err)
}
} So, the As we can also see, both packages are simply providing wrappers around the stdlib So, maybe we should take a look at the "crypto/rand" package. // Copyright 2010 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Package rand implements a cryptographically secure
// pseudorandom number generator.
package rand
import "io"
// Reader is a global, shared instance of a cryptographically
// strong pseudo-random generator.
//
// On Unix-like systems, Reader reads from /dev/urandom.
// On Linux, Reader uses getrandom(2) if available, /dev/urandom otherwise.
// On Windows systems, Reader uses the CryptGenRandom API.
var Reader io.Reader
// Read is a helper function that calls Reader.Read using io.ReadFull.
// On return, n == len(b) if and only if err == nil.
func Read(b []byte) (n int, err error) {
return io.ReadFull(Reader, b)
} As we can see in the comment of this package, the Read function will call out to a cryptographically strong pseudo-random generator. From the Wikipedia article describing CSPRNGs This paragraph seems important:
From here we can see that it really comes down to the hardware that your code is running on. There is pretty much nothing this library can do to increase the pool of entropy. This just seems like a groundless issue to me. Am I missing something here? |
Right. There's nothing magic about the It is an interesting design choice for a library author. It contradicts the recommendations of the Go maintainers, who write in Effective Go:
|
I agree that seems like an odd choice. Would be curious and interested to know which conditions the panic could be triggered IRL.
|
README from fork https://github.com/jaytaylor/uuid:
DEPRECATED DUE TO POOR RELIABILITY
PLEASE DO DO NOT USE!
This package is deprecated due to my having observed it generating duplicate UUID's in the wild from
uuid.NewV4()
.Recommendation
The current recommended UUID package for go is satori/go.uuid.
Also, RE: nu7hatch
If I could, I would also nuke nu7hatch/go-uuid from existence, as the core of this package is identical to it.
The text was updated successfully, but these errors were encountered: