Skip to content

Commit

Permalink
Fix race in NewUUID() (#64)
Browse files Browse the repository at this point in the history
* Fixed race in NewUUID()

* Remove unnecessary variable
  • Loading branch information
Andrey Abramov committed Jul 2, 2020
1 parent cb32006 commit 0e4e311
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions version1.go
Expand Up @@ -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 {
Expand All @@ -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
}

0 comments on commit 0e4e311

Please sign in to comment.