1
0
mirror of https://github.com/google/uuid.git synced 2024-11-24 08:32:23 +02:00

Fix race in NewUUID() (#64)

* Fixed race in NewUUID()

* Remove unnecessary variable
This commit is contained in:
Andrey Abramov 2020-07-02 21:56:42 +03:00 committed by GitHub
parent cb32006e48
commit 0e4e311974
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -17,12 +17,6 @@ import (
// //
// In most cases, New should be used. // In most cases, New should be used.
func NewUUID() (UUID, error) { func NewUUID() (UUID, error) {
nodeMu.Lock()
if nodeID == zeroID {
setNodeInterface("")
}
nodeMu.Unlock()
var uuid UUID var uuid UUID
now, seq, err := GetTime() now, seq, err := GetTime()
if err != nil { if err != nil {
@ -38,7 +32,13 @@ func NewUUID() (UUID, error) {
binary.BigEndian.PutUint16(uuid[4:], timeMid) binary.BigEndian.PutUint16(uuid[4:], timeMid)
binary.BigEndian.PutUint16(uuid[6:], timeHi) binary.BigEndian.PutUint16(uuid[6:], timeHi)
binary.BigEndian.PutUint16(uuid[8:], seq) binary.BigEndian.PutUint16(uuid[8:], seq)
nodeMu.Lock()
if nodeID == zeroID {
setNodeInterface("")
}
copy(uuid[10:], nodeID[:]) copy(uuid[10:], nodeID[:])
nodeMu.Unlock()
return uuid, nil return uuid, nil
} }