Skip to content

Commit

Permalink
Fix TID generator to avoid duplicates (#451)
Browse files Browse the repository at this point in the history
Third call on the same microsecond would not match the `if` condition
and would return the same value as the first call.
  • Loading branch information
bnewbold authored Dec 8, 2023
2 parents a18c4f4 + 069b301 commit 1c05892
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions repo/tid.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ func NextTID() string {
t := uint64(time.Now().UnixMicro())

ltLock.Lock()
if lastTime == t {
t++
if lastTime >= t {
t = lastTime + 1
}

lastTime = t
Expand Down

0 comments on commit 1c05892

Please sign in to comment.