Skip to content

Commit

Permalink
Fix a potential data race on a global variable
Browse files Browse the repository at this point in the history
  • Loading branch information
pior committed Mar 4, 2022
1 parent 3f90bc7 commit 3c7163e
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 3c7163e

Please sign in to comment.