Merge pull request #20431 from hashicorp/jbardin/state-uuid

remove single rand source to prevent races
This commit is contained in:
James Bardin 2019-02-22 10:40:51 -05:00 committed by GitHub
commit 9561ec4617
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 1 additions and 14 deletions

View File

@ -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)