Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(*): enable gosec/godot linter #404

Merged
merged 1 commit into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ linters:
- errorlint
- exportloopref
# - gocritic
# - godot
- godot
# - gomoddirectives
# - gosec
- gosec
- nakedret
- nilerr
- nilnil
Expand Down Expand Up @@ -79,4 +79,5 @@ issues:
exclude-rules:
- path: _test\.go
linters:
- unparam
- unparam
- gosec
8 changes: 6 additions & 2 deletions common/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"net"
"net/http"
"os"
"time"

"github.com/pkg/errors"
"github.com/prometheus/client_golang/prometheus/promhttp"
Expand Down Expand Up @@ -100,8 +101,11 @@ func Start(bindAddress string) (*PrometheusMetrics, error) {
}

p := &PrometheusMetrics{
server: &http.Server{Handler: mux},
port: listener.Addr().(*net.TCPAddr).Port,
server: &http.Server{
Handler: mux,
ReadHeaderTimeout: time.Second,
},
port: listener.Addr().(*net.TCPAddr).Port,
}

slog.Info(fmt.Sprintf("Serving Prometheus metrics at http://localhost:%d/metrics", p.port))
Expand Down
8 changes: 5 additions & 3 deletions common/pprof.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ import (
"io"
"log/slog"
"net/http"
_ "net/http/pprof"
_ "net/http/pprof" //nolint:gosec
"os"
"runtime/pprof"
"time"
)

var (
Expand All @@ -48,8 +49,9 @@ func DoWithLabels(labels map[string]string, f func()) {

func RunProfiling() io.Closer {
s := &http.Server{
Addr: PprofBindAddress,
Handler: http.DefaultServeMux,
Addr: PprofBindAddress,
Handler: http.DefaultServeMux,
ReadHeaderTimeout: time.Second,
}

if !PprofEnable {
Expand Down
2 changes: 1 addition & 1 deletion coordinator/impl/metadata_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func (m *metadataProviderFile) Store(cs *model.ClusterStatus, expectedVersion Ve
return "", err
}

if err := os.WriteFile(m.path, newContent, 0640); err != nil {
if err := os.WriteFile(m.path, newContent, 0600); err != nil {
return MetadataNotExists, err
}

Expand Down
2 changes: 1 addition & 1 deletion coordinator/impl/shard_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ func (s *shardController) selectNewLeader(newTermResponses map[model.ServerAddre
}

// Select a random leader among the nodes with the highest entry in the wal
leader = candidates[rand.Intn(len(candidates))]
leader = candidates[rand.Intn(len(candidates))] //nolint:gosec
followers = make(map[model.ServerAddress]*proto.EntryId)
for a, e := range newTermResponses {
if a != leader {
Expand Down
4 changes: 2 additions & 2 deletions oxia/async_client_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,10 @@ func (c *clientImpl) List(ctx context.Context, minKeyInclusive string, maxKeyExc
ch := make(chan ListResult)
wg := common.NewWaitGroup(len(shardIds))
for _, shardId := range shardIds {
shardIdPtr := &shardId
shardIdPtr := shardId
go func() {
request := &proto.ListRequest{
ShardId: shardIdPtr,
ShardId: &shardIdPtr,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like it was an actual bug, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Old implement is an bug(before go1.22 and go1.21

StartInclusive: minKeyInclusive,
EndExclusive: maxKeyExclusive,
}
Expand Down
4 changes: 2 additions & 2 deletions perf/perf.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func (p *perf) generateWriteTraffic(ctx context.Context, client oxia.AsyncClient
return
}

key := p.keys[rand.Intn(int(p.config.KeysCardinality))]
key := p.keys[rand.Intn(int(p.config.KeysCardinality))] //nolint:gosec

start := time.Now()
ch := client.Put(key, value)
Expand Down Expand Up @@ -188,7 +188,7 @@ func (p *perf) generateReadTraffic(ctx context.Context, client oxia.AsyncClient,
return
}

key := p.keys[rand.Intn(int(p.config.KeysCardinality))]
key := p.keys[rand.Intn(int(p.config.KeysCardinality))] //nolint:gosec

start := time.Now()
ch := client.Get(key)
Expand Down
Loading