Skip to content

Commit 0e4e311

Browse files
author
Andrey Abramov
authored
Fix race in NewUUID() (#64)
* Fixed race in NewUUID() * Remove unnecessary variable
1 parent cb32006 commit 0e4e311

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

version1.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,6 @@ import (
1717
//
1818
// In most cases, New should be used.
1919
func NewUUID() (UUID, error) {
20-
nodeMu.Lock()
21-
if nodeID == zeroID {
22-
setNodeInterface("")
23-
}
24-
nodeMu.Unlock()
25-
2620
var uuid UUID
2721
now, seq, err := GetTime()
2822
if err != nil {
@@ -38,7 +32,13 @@ func NewUUID() (UUID, error) {
3832
binary.BigEndian.PutUint16(uuid[4:], timeMid)
3933
binary.BigEndian.PutUint16(uuid[6:], timeHi)
4034
binary.BigEndian.PutUint16(uuid[8:], seq)
35+
36+
nodeMu.Lock()
37+
if nodeID == zeroID {
38+
setNodeInterface("")
39+
}
4140
copy(uuid[10:], nodeID[:])
41+
nodeMu.Unlock()
4242

4343
return uuid, nil
4444
}

0 commit comments

Comments
 (0)