Skip to content

Commit

Permalink
copyblocks: Satisfy and enable gosec rule G114 (#10330)
Browse files Browse the repository at this point in the history
Signed-off-by: Arve Knudsen <[email protected]>
  • Loading branch information
aknuds1 authored Jan 2, 2025
1 parent e44f6c0 commit 04642c0
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 6 deletions.
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ linters-settings:
gosec:
includes:
- G108
- G114

run:
timeout: 10m
Expand Down
7 changes: 6 additions & 1 deletion pkg/mimirtool/commands/alerts.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,12 @@ func (a *AlertCommand) verifyConfig(_ *kingpin.ParseContext) error {
))

go func() {
log.Fatal(http.ListenAndServe(":9090", nil))
server := http.Server{
Addr: ":9090",
ReadTimeout: 10 * time.Second,
WriteTimeout: 10 * time.Second,
}
log.Fatal(server.ListenAndServe())
}()

ctx := context.Background()
Expand Down
8 changes: 6 additions & 2 deletions pkg/mimirtool/commands/loadgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,12 @@ func (c *LoadgenCommand) run(_ *kingpin.ParseContext) error {

http.Handle("/metrics", promhttp.Handler())
go func() {
err := http.ListenAndServe(c.metricsListenAddress, nil)
if err != nil {
server := http.Server{
Addr: c.metricsListenAddress,
ReadTimeout: 10 * time.Second,
WriteTimeout: 10 * time.Second,
}
if err := server.ListenAndServe(); err != nil {
logrus.WithError(err).Errorln("metrics listener failed")
}
}()
Expand Down
8 changes: 6 additions & 2 deletions tools/copyblocks/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,12 @@ func main() {
go func() {
level.Info(logger).Log("msg", "HTTP server listening on "+cfg.httpListen)
http.Handle("/metrics", promhttp.Handler())
err := http.ListenAndServe(cfg.httpListen, nil)
if err != nil {
server := &http.Server{
Addr: cfg.httpListen,
ReadTimeout: 10 * time.Second,
WriteTimeout: 10 * time.Second,
}
if err := server.ListenAndServe(); err != nil {
level.Error(logger).Log("msg", "failed to start HTTP server")
os.Exit(1)
}
Expand Down
7 changes: 6 additions & 1 deletion tools/trafficdump/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,12 @@ func main() {
if *httpServer != "" {
go func() {
log.Println("HTTP server running on", *httpServer)
log.Println(http.ListenAndServe(*httpServer, nil))
server := &http.Server{
Addr: *httpServer,
ReadTimeout: 10 * time.Second,
WriteTimeout: 10 * time.Second,
}
log.Println(server.ListenAndServe())
}()
}

Expand Down

0 comments on commit 04642c0

Please sign in to comment.