diff --git a/pkg/artifactcache/handler.go b/pkg/artifactcache/handler.go index 90d4218f29b..bc9f6440153 100644 --- a/pkg/artifactcache/handler.go +++ b/pkg/artifactcache/handler.go @@ -96,7 +96,7 @@ func StartHandler(dir, customExternalURL string, outboundIP string, port uint16, h.gcCache() - listener, err := net.Listen("tcp", fmt.Sprintf(":%d", port)) // listen on all interfaces + listener, err := net.Listen("tcp4", fmt.Sprintf(":%d", port)) // listen on all interfaces if err != nil { return nil, err } @@ -106,6 +106,7 @@ func StartHandler(dir, customExternalURL string, outboundIP string, port uint16, Handler: router, } go func() { + logger.Infof("Start artifactcache server on http://0.0.0.0:%d", port) if err := server.Serve(listener); err != nil && errors.Is(err, net.ErrClosed) { logger.Errorf("http serve: %v", err) } diff --git a/pkg/artifacts/server.go b/pkg/artifacts/server.go index c3207f10dee..dee474f861e 100644 --- a/pkg/artifacts/server.go +++ b/pkg/artifacts/server.go @@ -7,6 +7,7 @@ import ( "fmt" "io" "io/fs" + "net" "net/http" "os" "path/filepath" @@ -291,16 +292,20 @@ func Serve(ctx context.Context, artifactPath string, addr string, port string) c downloads(router, artifactPath, fsys) RoutesV4(router, artifactPath, fsys, fsys) + listener, err := net.Listen("tcp4", fmt.Sprintf("%s:%s", addr, port)) + if err != nil { + logger.Fatal(err) + } + server := &http.Server{ - Addr: fmt.Sprintf("%s:%s", addr, port), ReadHeaderTimeout: 2 * time.Second, Handler: router, } // run server go func() { - logger.Infof("Start server on http://%s:%s", addr, port) - if err := server.ListenAndServe(); err != nil && err != http.ErrServerClosed { + logger.Infof("Start artifact server on http://%s:%s", addr, port) + if err := server.Serve(listener); err != nil && err != http.ErrServerClosed { logger.Fatal(err) } }()