From 43b2c9a1d0a49362f7c1e4bdcfd90f8264783cbe Mon Sep 17 00:00:00 2001 From: James Bardin Date: Thu, 21 Feb 2019 20:45:41 -0500 Subject: [PATCH] remove single rand source to prevent races This shouldn't really be an issue in normal usage, but some of the backend tests will trigger a race here. --- state/state.go | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/state/state.go b/state/state.go index 04707bccb..21cd90387 100644 --- a/state/state.go +++ b/state/state.go @@ -3,7 +3,6 @@ package state import ( "context" "fmt" - "math/rand" "os" "os/user" "time" @@ -14,12 +13,6 @@ import ( "github.com/hashicorp/terraform/version" ) -var rngSource *rand.Rand - -func init() { - rngSource = rand.New(rand.NewSource(time.Now().UnixNano())) -} - // State is a deprecated alias for statemgr.Full type State = statemgr.Full @@ -82,13 +75,7 @@ func LockWithContext(ctx context.Context, s State, info *LockInfo) (string, erro // Generate a LockInfo structure, populating the required fields. func NewLockInfo() *LockInfo { - // this doesn't need to be cryptographically secure, just unique. - // Using math/rand alleviates the need to check handle the read error. - // Use a uuid format to match other IDs used throughout Terraform. - buf := make([]byte, 16) - rngSource.Read(buf) - - id, err := uuid.FormatUUID(buf) + id, err := uuid.GenerateUUID() if err != nil { // this of course shouldn't happen panic(err)