From 133271ea6920ca3ef3f3d15b6c302c4383f62b09 Mon Sep 17 00:00:00 2001 From: Dan Stough Date: Sat, 18 Feb 2023 14:58:39 -0500 Subject: [PATCH] fix: revert go mod compat for sdk,api to 1.19 (#16323) --- api/go.mod | 2 +- envoyextensions/go.mod | 2 +- sdk/freeport/freeport.go | 6 +++++- sdk/go.mod | 2 +- troubleshoot/go.mod | 2 +- 5 files changed, 9 insertions(+), 5 deletions(-) diff --git a/api/go.mod b/api/go.mod index d9a68569d..c987fde1a 100644 --- a/api/go.mod +++ b/api/go.mod @@ -1,6 +1,6 @@ module github.com/hashicorp/consul/api -go 1.20 +go 1.19 replace github.com/hashicorp/consul/sdk => ../sdk diff --git a/envoyextensions/go.mod b/envoyextensions/go.mod index 5a73e969c..f96560804 100644 --- a/envoyextensions/go.mod +++ b/envoyextensions/go.mod @@ -1,6 +1,6 @@ module github.com/hashicorp/consul/envoyextensions -go 1.20 +go 1.19 replace github.com/hashicorp/consul/api => ../api diff --git a/sdk/freeport/freeport.go b/sdk/freeport/freeport.go index 6c275fe86..c51ef9815 100644 --- a/sdk/freeport/freeport.go +++ b/sdk/freeport/freeport.go @@ -76,6 +76,9 @@ var ( // total is the total number of available ports in the block for use. total int + // seededRand is a random generator that is pre-seeded from the current time. + seededRand *rand.Rand + // stopCh is used to signal to background goroutines to terminate. Only // really exists for the safety of reset() during unit tests. stopCh chan struct{} @@ -114,6 +117,7 @@ func initialize() { panic("freeport: block size too big or too many blocks requested") } + seededRand = rand.New(rand.NewSource(time.Now().UnixNano())) // This is compatible with go 1.19 but unnecessary in >= go1.20 firstPort, lockLn = alloc() condNotEmpty = sync.NewCond(&mu) @@ -255,7 +259,7 @@ func adjustMaxBlocks() (int, error) { // be automatically released when the application terminates. func alloc() (int, net.Listener) { for i := 0; i < attempts; i++ { - block := int(rand.Int31n(int32(effectiveMaxBlocks))) + block := int(seededRand.Int31n(int32(effectiveMaxBlocks))) firstPort := lowPort + block*blockSize ln, err := net.ListenTCP("tcp", tcpAddr("127.0.0.1", firstPort)) if err != nil { diff --git a/sdk/go.mod b/sdk/go.mod index 63ad3671a..8a04b9e10 100644 --- a/sdk/go.mod +++ b/sdk/go.mod @@ -1,6 +1,6 @@ module github.com/hashicorp/consul/sdk -go 1.20 +go 1.19 require ( github.com/hashicorp/go-cleanhttp v0.5.1 diff --git a/troubleshoot/go.mod b/troubleshoot/go.mod index cf82c88f1..c4e445ee0 100644 --- a/troubleshoot/go.mod +++ b/troubleshoot/go.mod @@ -1,6 +1,6 @@ module github.com/hashicorp/consul/troubleshoot -go 1.20 +go 1.19 replace github.com/hashicorp/consul/api => ../api