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.
This commit is contained in:
parent
c40530afb0
commit
43b2c9a1d0
|
@ -3,7 +3,6 @@ package state
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/rand"
|
|
||||||
"os"
|
"os"
|
||||||
"os/user"
|
"os/user"
|
||||||
"time"
|
"time"
|
||||||
|
@ -14,12 +13,6 @@ import (
|
||||||
"github.com/hashicorp/terraform/version"
|
"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
|
// State is a deprecated alias for statemgr.Full
|
||||||
type State = 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.
|
// Generate a LockInfo structure, populating the required fields.
|
||||||
func NewLockInfo() *LockInfo {
|
func NewLockInfo() *LockInfo {
|
||||||
// this doesn't need to be cryptographically secure, just unique.
|
id, err := uuid.GenerateUUID()
|
||||||
// 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)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// this of course shouldn't happen
|
// this of course shouldn't happen
|
||||||
panic(err)
|
panic(err)
|
||||||
|
|
Loading…
Reference in New Issue