Skip to content

Commit

Permalink
Fix DeepSource errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ykadowak committed Sep 26, 2023
1 parent bdc9c70 commit f7ffd6a
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 12 deletions.
2 changes: 1 addition & 1 deletion internal/config/corrector.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (c *Corrector) GetStreamListConcurrency() int {
return 200 //nolint:gomnd
}

// Returns 2048 when not specified since not setting this could use up all the available momory
// GetBboltAsyncWriteConcurrency returns 2048 when not specified since not setting this could use up all the available momory
func (c *Corrector) GetBboltAsyncWriteConcurrency() int {
if c != nil {
return c.BboltAsyncWriteConcurrency
Expand Down
3 changes: 2 additions & 1 deletion internal/net/grpc/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import (

type contextKey string

// exported only for testing
// GrpcMethodContextKey represents a context key for grpc method.
// This is exported only for testing.
const GrpcMethodContextKey contextKey = "grpc_method"

// WrapGRPCMethod returns a copy of parent in which the method associated with key (grpcMethodContextKey).
Expand Down
10 changes: 7 additions & 3 deletions internal/servers/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"crypto/tls"
"net/http"
"os"
"path/filepath"
"reflect"
"strconv"
"syscall"
Expand Down Expand Up @@ -128,6 +129,7 @@ type grpcKeepalive struct {
permitWithoutStream bool
}

// skipcq: GO-R1005
func New(opts ...Option) (Server, error) {
srv := new(server)

Expand Down Expand Up @@ -253,6 +255,7 @@ func (s *server) Name() string {
return s.name
}

// skipcq: GO-R1005
func (s *server) ListenAndServe(ctx context.Context, ech chan<- error) (err error) {
if !s.IsRunning() {
s.mu.Lock()
Expand All @@ -274,8 +277,8 @@ func (s *server) ListenAndServe(ctx context.Context, ech chan<- error) (err erro
return s.network.String()
}(), func() string {
if s.network == net.UNIX {
if len(s.socketPath) == 0 {
s.socketPath = os.TempDir() + string(os.PathSeparator) + s.name + "." + strconv.Itoa(os.Getpid()) + ".sock"
if s.socketPath == "" {
s.socketPath = filepath.Join(os.TempDir(), string(os.PathSeparator), s.name, ".", strconv.Itoa(os.Getpid()), ".sock")
}
return s.socketPath
}
Expand Down Expand Up @@ -339,6 +342,7 @@ func (s *server) ListenAndServe(ctx context.Context, ech chan<- error) (err erro
return nil
}

// skipcq: GO-R1005
func (s *server) Shutdown(ctx context.Context) (rerr error) {
if !s.IsRunning() {
return nil
Expand Down Expand Up @@ -385,7 +389,7 @@ func (s *server) Shutdown(ctx context.Context) (rerr error) {
}
}

if len(s.socketPath) != 0 {
if s.socketPath != "" {
defer func() {
err := os.RemoveAll(s.socketPath)
if err != nil {
Expand Down
7 changes: 3 additions & 4 deletions pkg/index/job/correction/service/corrector.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,10 @@ func (c *correct) Start(ctx context.Context) (<-chan error, error) {

func (c *correct) PreStop(_ context.Context) error {
log.Info("removing persistent cache files...")
if err := c.checkedID.Close(true); err != nil {
return err
}
return nil
return c.checkedID.Close(true)
}

// skipcq: GO-R1005
func (c *correct) correct(ctx context.Context) (err error) {
// leftAgentAddrs is the agents' addr that hasn't been corrected yet.
// This is used to know which agents possibly have the same index as the target replica.
Expand Down Expand Up @@ -381,6 +379,7 @@ func (c *correct) correctTimestamp(ctx context.Context, targetReplica *vectorRep
return nil
}

// skipcq: CRT-D0001
allReplicas := append(foundReplicas, targetReplica)

// sort by timestamp
Expand Down
4 changes: 2 additions & 2 deletions pkg/index/job/correction/service/corrector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ type mockDiscovererClient struct {
client mock.ClientInternal
}

func (*mockDiscovererClient) Start(ctx context.Context) (<-chan error, error) {
func (*mockDiscovererClient) Start(context.Context) (<-chan error, error) {
return nil, nil
}

func (*mockDiscovererClient) GetAddrs(ctx context.Context) []string {
func (*mockDiscovererClient) GetAddrs(context.Context) []string {
return nil
}

Expand Down
3 changes: 2 additions & 1 deletion pkg/index/job/correction/usecase/corrector.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ func (r *run) Start(ctx context.Context) (<-chan error, error) {
p, err := os.FindProcess(os.Getpid())
if err != nil {
// using Fatal to avoid this process to be zombie
// skipcq: RVV-A0003
log.Fatalf("failed to find my pid to kill %v", err)
return
}
Expand Down Expand Up @@ -216,6 +217,6 @@ func (r *run) Stop(ctx context.Context) error {
return nil
}

func (*run) PostStop(ctx context.Context) error {
func (*run) PostStop(_ context.Context) error {
return nil
}

0 comments on commit f7ffd6a

Please sign in to comment.