Skip to content

Commit

Permalink
Merge pull request #2171 from Shopify/fix-version-race
Browse files Browse the repository at this point in the history
fix: potential data race on a global variable
  • Loading branch information
dnwe committed Mar 7, 2022
2 parents 3f90bc7 + 3c7163e commit 7b9f4c6
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions version.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
package sarama

import "runtime/debug"
import (
"runtime/debug"
"sync"
)

var v string
var (
v string
vOnce sync.Once
)

func version() string {
if v == "" {
vOnce.Do(func() {
bi, ok := debug.ReadBuildInfo()
if ok {
v = bi.Main.Version
Expand All @@ -15,6 +21,6 @@ func version() string {
// the version
v = "dev"
}
}
})
return v
}

0 comments on commit 7b9f4c6

Please sign in to comment.