Skip to content

Commit 086f43d

Browse files
committed
lint: fix issues with go 1.20
Signed-off-by: CrazyMax <[email protected]>
1 parent 18210e2 commit 086f43d

File tree

6 files changed

+15
-17
lines changed

6 files changed

+15
-17
lines changed

cmd/buildkitd/debug.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"net/http"
77
"net/http/pprof"
88
"runtime"
9+
"time"
910

1011
"github.com/sirupsen/logrus"
1112
"golang.org/x/net/trace"
@@ -36,7 +37,12 @@ func setupDebugHandlers(addr string) error {
3637
if err != nil {
3738
return err
3839
}
40+
server := &http.Server{
41+
Addr: l.Addr().String(),
42+
Handler: m,
43+
ReadHeaderTimeout: time.Minute,
44+
}
3945
logrus.Debugf("debug handlers listening at %s", addr)
40-
go http.Serve(l, m)
46+
go server.ListenAndServe()
4147
return nil
4248
}

frontend/gateway/container.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ type gatewayContainer struct {
293293
cancel func()
294294
}
295295

296-
func (gwCtr *gatewayContainer) Start(ctx context.Context, req client.StartRequest) (client.ContainerProcess, error) {
296+
func (gwCtr *gatewayContainer) Start(_ context.Context, req client.StartRequest) (client.ContainerProcess, error) {
297297
resize := make(chan executor.WinSize)
298298
signal := make(chan syscall.Signal)
299299
procInfo := executor.ProcessInfo{

solver/scheduler_test.go

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
)
2323

2424
func init() {
25+
rand.Seed(time.Now().UnixNano()) //nolint:staticcheck // Ignore SA1019. No way to get the automatically generated seed since Go 1.20.
2526
if debugScheduler {
2627
logrus.SetOutput(os.Stdout)
2728
logrus.SetLevel(logrus.DebugLevel)
@@ -716,8 +717,6 @@ func TestHugeGraph(t *testing.T) {
716717
t.Parallel()
717718
ctx := context.TODO()
718719

719-
rand.Seed(time.Now().UnixNano())
720-
721720
cacheManager := newTrackingCacheManager(NewInMemoryCacheManager())
722721

723722
l := NewSolver(SolverOpt{
@@ -1036,8 +1035,6 @@ func TestSlowCache(t *testing.T) {
10361035
t.Parallel()
10371036
ctx := context.TODO()
10381037

1039-
rand.Seed(time.Now().UnixNano())
1040-
10411038
l := NewSolver(SolverOpt{
10421039
ResolveOpFunc: testOpResolver,
10431040
})
@@ -1117,8 +1114,6 @@ func TestParallelInputs(t *testing.T) {
11171114
t.Parallel()
11181115
ctx := context.TODO()
11191116

1120-
rand.Seed(time.Now().UnixNano())
1121-
11221117
l := NewSolver(SolverOpt{
11231118
ResolveOpFunc: testOpResolver,
11241119
})
@@ -1175,8 +1170,6 @@ func TestErrorReturns(t *testing.T) {
11751170
t.Parallel()
11761171
ctx := context.TODO()
11771172

1178-
rand.Seed(time.Now().UnixNano())
1179-
11801173
l := NewSolver(SolverOpt{
11811174
ResolveOpFunc: testOpResolver,
11821175
})
@@ -3047,8 +3040,6 @@ func TestCacheExportingMergedKey(t *testing.T) {
30473040
func TestMergedEdgesLookup(t *testing.T) {
30483041
t.Parallel()
30493042

3050-
rand.Seed(time.Now().UnixNano())
3051-
30523043
// this test requires multiple runs to trigger the race
30533044
for i := 0; i < 20; i++ {
30543045
func() {
@@ -3102,8 +3093,6 @@ func TestMergedEdgesLookup(t *testing.T) {
31023093
func TestCacheLoadError(t *testing.T) {
31033094
t.Parallel()
31043095

3105-
rand.Seed(time.Now().UnixNano())
3106-
31073096
ctx := context.TODO()
31083097

31093098
cacheManager := newTrackingCacheManager(NewInMemoryCacheManager())

source/http/httpsource.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,9 @@ func (hs *httpSourceHandler) Snapshot(ctx context.Context, g session.Group) (cac
392392
if err != nil {
393393
return nil, err
394394
}
395+
defer func() {
396+
_ = resp.Body.Close()
397+
}()
395398

396399
ref, dgst, err := hs.save(ctx, resp, g)
397400
if err != nil {

util/compression/compression.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ const (
8181
mediaTypeImageLayerZstd = ocispecs.MediaTypeImageLayer + "+zstd" // unreleased image-spec#790
8282
)
8383

84-
var Default gzipType = Gzip
84+
var Default = Gzip
8585

8686
func parse(t string) (Type, error) {
8787
switch t {

util/testutil/integration/run.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,8 @@ func Run(t *testing.T, testCases []Test, opt ...TestOpt) {
164164

165165
list := List()
166166
if os.Getenv("BUILDKIT_WORKER_RANDOM") == "1" && len(list) > 0 {
167-
rand.Seed(time.Now().UnixNano())
168-
list = []Worker{list[rand.Intn(len(list))]} //nolint:gosec // using math/rand is fine in a test utility
167+
rng := rand.New(rand.NewSource(time.Now().UnixNano())) //nolint:gosec // using math/rand is fine in a test utility
168+
list = []Worker{list[rng.Intn(len(list))]}
169169
}
170170

171171
for _, br := range list {

0 commit comments

Comments
 (0)