Skip to content

Commit

Permalink
Enable gosec G112 rule (#10333)
Browse files Browse the repository at this point in the history
Signed-off-by: Arve Knudsen <[email protected]>
  • Loading branch information
aknuds1 authored Jan 3, 2025
1 parent a51e622 commit b99f117
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 4 deletions.
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ linters-settings:
includes:
- G108
- G109
- G112
- G114

run:
Expand Down
10 changes: 9 additions & 1 deletion pkg/frontend/frontend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ func TestFrontend_RequestHostHeaderWhenDownstreamURLIsConfigured(t *testing.T) {
_, err := w.Write([]byte(responseBody))
require.NoError(t, err)
}),
ReadTimeout: 10 * time.Second,
WriteTimeout: 10 * time.Second,
}

defer downstreamServer.Shutdown(context.Background()) //nolint:errcheck
Expand Down Expand Up @@ -111,6 +113,8 @@ func TestFrontend_LogsSlowQueriesFormValues(t *testing.T) {
_, err := w.Write([]byte(responseBody))
require.NoError(t, err)
}),
ReadTimeout: 10 * time.Second,
WriteTimeout: 10 * time.Second,
}

defer downstreamServer.Shutdown(context.Background()) //nolint:errcheck
Expand Down Expand Up @@ -173,6 +177,8 @@ func TestFrontend_ReturnsRequestBodyTooLargeError(t *testing.T) {
_, err := w.Write([]byte(responseBody))
require.NoError(t, err)
}),
ReadTimeout: 10 * time.Second,
WriteTimeout: 10 * time.Second,
}

defer downstreamServer.Shutdown(context.Background()) //nolint:errcheck
Expand Down Expand Up @@ -260,7 +266,9 @@ func testFrontend(t *testing.T, config CombinedFrontendConfig, handler http.Hand
).Wrap(transport.NewHandler(config.Handler, rt, logger, nil, nil)))

httpServer := http.Server{
Handler: r,
Handler: r,
ReadTimeout: 10 * time.Second,
WriteTimeout: 10 * time.Second,
}
defer httpServer.Shutdown(context.Background()) //nolint:errcheck

Expand Down
4 changes: 3 additions & 1 deletion pkg/frontend/v1/frontend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,9 @@ func testFrontend(t *testing.T, config Config, handler http.Handler, test func(a
).Wrap(transport.NewHandler(handlerCfg, rt, logger, nil, nil)))

httpServer := http.Server{
Handler: r,
Handler: r,
ReadTimeout: 10 * time.Second,
WriteTimeout: 10 * time.Second,
}
defer httpServer.Shutdown(context.Background()) //nolint:errcheck

Expand Down
5 changes: 4 additions & 1 deletion pkg/util/gziphandler/gzip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"os"
"strconv"
"testing"
"time"

"github.com/stretchr/testify/assert"
)
Expand Down Expand Up @@ -279,7 +280,9 @@ func TestGzipHandlerContentLength(t *testing.T) {
}
defer ln.Close()
srv := &http.Server{
Handler: nil,
Handler: nil,
ReadTimeout: 10 * time.Second,
WriteTimeout: 10 * time.Second,
}
go func() { _ = srv.Serve(ln) }()

Expand Down
5 changes: 4 additions & 1 deletion pkg/util/instrumentation/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"fmt"
"net"
"net/http"
"time"

"github.com/go-kit/log"
"github.com/go-kit/log/level"
Expand Down Expand Up @@ -45,7 +46,9 @@ func (s *MetricsServer) Start() error {
router.Handle("/metrics", promhttp.HandlerFor(s.registry, promhttp.HandlerOpts{}))

s.srv = &http.Server{
Handler: router,
Handler: router,
ReadTimeout: 10 * time.Second,
WriteTimeout: 10 * time.Second,
}

go func() {
Expand Down

0 comments on commit b99f117

Please sign in to comment.