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

[patch] bugfix lb-gateway's Insert rpc nil pointer panic #980

Merged
merged 5 commits into from
Feb 4, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 5 additions & 3 deletions internal/safety/safety.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package safety

import (
"runtime"
"runtime/debug"

"github.com/vdaas/vald/internal/errors"
"github.com/vdaas/vald/internal/info"
Expand All @@ -37,12 +38,13 @@ func recoverFunc(fn func() error, withPanic bool) func() error {
return func() (err error) {
defer func() {
if r := recover(); r != nil {
log.Warnf("recovered:\t%+v", r)
stack := string(debug.Stack())
log.Warn("recovered: %+v\nstacktrace:\n%s", r, stack)
switch x := r.(type) {
case runtime.Error:
err = errors.ErrRuntimeError(err, x)
if withPanic {
log.Error(err, info.Get())
log.Errorf("recovered but this thread going to panic because panic reason is runtimer.Error\nerror: %v\ninfo:\n%s\nstacktrace:\n%s", err, info.Get().String(), stack)
kpango marked this conversation as resolved.
Show resolved Hide resolved
panic(err)
}
case string:
Expand All @@ -53,7 +55,7 @@ func recoverFunc(fn func() error, withPanic bool) func() error {
err = errors.ErrPanicRecovered(err, x)
}
if err != nil {
log.Error(err, info.Get())
log.Errorf("recovered error: %v\ninfo:\n%s\nstacktrace:\n%s", err, info.Get().String(), stack)
}
}
}()
Expand Down
9 changes: 7 additions & 2 deletions pkg/gateway/backup/handler/grpc/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ func (s *server) MultiInsert(ctx context.Context, reqs *payload.Insert_MultiRequ
}
return nil, err
}
if reqs.Requests[i] != nil {
if reqs.Requests[i].GetConfig() != nil {
reqs.Requests[i].Config.SkipStrictExistCheck = true
} else {
reqs.Requests[i].Config = &payload.Insert_Config{SkipStrictExistCheck: true}
Expand Down Expand Up @@ -1374,7 +1374,7 @@ func (s *server) MultiRemove(ctx context.Context, reqs *payload.Remove_MultiRequ
}
}()
ids := make([]string, 0, len(reqs.GetRequests()))
for _, req := range reqs.GetRequests() {
for i, req := range reqs.GetRequests() {
id := req.GetId()
ids = append(ids, id.GetId())
if !req.GetConfig().GetSkipStrictExistCheck() {
Expand All @@ -1400,6 +1400,11 @@ func (s *server) MultiRemove(ctx context.Context, reqs *payload.Remove_MultiRequ
}
return nil, err
}
if reqs.Requests[i].GetConfig() != nil {
reqs.Requests[i].Config.SkipStrictExistCheck = true
} else {
reqs.Requests[i].Config = &payload.Remove_Config{SkipStrictExistCheck: true}
}
}
}
locs, err = s.gateway.MultiRemove(ctx, reqs, s.copts...)
Expand Down
8 changes: 7 additions & 1 deletion pkg/gateway/lb/handler/grpc/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -1686,7 +1686,7 @@ func (s *server) MultiRemove(ctx context.Context, reqs *payload.Remove_MultiRequ
}
}()
ids := make([]string, 0, len(reqs.GetRequests()))
for _, req := range reqs.GetRequests() {
for i, req := range reqs.GetRequests() {
id := req.GetId()
ids = append(ids, id.GetId())
if !req.GetConfig().GetSkipStrictExistCheck() {
Expand All @@ -1712,6 +1712,12 @@ func (s *server) MultiRemove(ctx context.Context, reqs *payload.Remove_MultiRequ
}
return nil, err
}
if reqs.Requests[i].GetConfig() != nil {
reqs.Requests[i].Config.SkipStrictExistCheck = true
} else {
reqs.Requests[i].Config = &payload.Remove_Config{SkipStrictExistCheck: true}
}

kpango marked this conversation as resolved.
Show resolved Hide resolved
}
}
var mu sync.Mutex
Expand Down