1
0
mirror of https://github.com/google/uuid.git synced 2025-09-16 09:16:30 +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

View File

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