Skip to content

Commit

Permalink
[bugfix] add target length validation for each grpc client exection m…
Browse files Browse the repository at this point in the history
…ethod

Signed-off-by: kpango <[email protected]>
  • Loading branch information
kpango committed Feb 2, 2023
1 parent f529cbd commit e004aae
Show file tree
Hide file tree
Showing 16 changed files with 365 additions and 488 deletions.
382 changes: 115 additions & 267 deletions apis/grpc/v1/payload/payload_vtproto.pb.go

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions example/client/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ replace (
golang.org/x/crypto => golang.org/x/crypto v0.5.0
golang.org/x/net => golang.org/x/net v0.5.0
golang.org/x/text => golang.org/x/text v0.6.0
google.golang.org/genproto => google.golang.org/genproto v0.0.0-20230123190316-2c411cf9d197
google.golang.org/grpc => google.golang.org/grpc v1.52.0
google.golang.org/genproto => google.golang.org/genproto v0.0.0-20230131230820-1c016267d619
google.golang.org/grpc => google.golang.org/grpc v1.52.3
google.golang.org/protobuf => google.golang.org/protobuf v1.28.1
gopkg.in/yaml.v2 => gopkg.in/yaml.v2 v2.4.0
gopkg.in/yaml.v3 => gopkg.in/yaml.v3 v3.0.1
Expand Down
8 changes: 4 additions & 4 deletions example/client/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ golang.org/x/text v0.6.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gonum.org/v1/hdf5 v0.0.0-20210714002203-8c5d23bc6946 h1:vJpL69PeUullhJyKtTjHjENEmZU3BkO4e+fod7nKzgM=
gonum.org/v1/hdf5 v0.0.0-20210714002203-8c5d23bc6946/go.mod h1:BQUWDHIAygjdt1HnUPQ0eWqLN2n5FwJycrpYUVUOx2I=
google.golang.org/genproto v0.0.0-20230123190316-2c411cf9d197 h1:BwjeHhu4HS48EZmu1nS7flldBIDPC3qn+HqaSQ1K4x8=
google.golang.org/genproto v0.0.0-20230123190316-2c411cf9d197/go.mod h1:RGgjbofJ8xD9Sq1VVhDM1Vok1vRONV+rg+CjzG4SZKM=
google.golang.org/grpc v1.52.0 h1:kd48UiU7EHsV4rnLyOJRuP/Il/UHE7gdDAQ+SZI7nZk=
google.golang.org/grpc v1.52.0/go.mod h1:pu6fVzoFb+NBYNAvQL08ic+lvB2IojljRYuun5vorUY=
google.golang.org/genproto v0.0.0-20230131230820-1c016267d619 h1:p0kMzw6AG0JEzd7Z+kXqOiLhC6gjUQTbtS2zR0Q3DbI=
google.golang.org/genproto v0.0.0-20230131230820-1c016267d619/go.mod h1:RGgjbofJ8xD9Sq1VVhDM1Vok1vRONV+rg+CjzG4SZKM=
google.golang.org/grpc v1.52.3 h1:pf7sOysg4LdgBqduXveGKrcEwbStiK2rtfghdzlUYDQ=
google.golang.org/grpc v1.52.3/go.mod h1:pu6fVzoFb+NBYNAvQL08ic+lvB2IojljRYuun5vorUY=
google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w=
google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
120 changes: 34 additions & 86 deletions go.mod

Large diffs are not rendered by default.

89 changes: 42 additions & 47 deletions go.sum

Large diffs are not rendered by default.

51 changes: 1 addition & 50 deletions hack/go.mod.default
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ replace (
github.com/ajstarks/deck => github.com/ajstarks/deck latest
github.com/ajstarks/deck/generate => github.com/ajstarks/deck/generate latest
github.com/ajstarks/svgo => github.com/ajstarks/svgo latest
github.com/alecthomas/units => github.com/alecthomas/units latest
github.com/alexflint/go-filemutex => github.com/alexflint/go-filemutex latest
github.com/antihax/optional => github.com/antihax/optional latest
github.com/armon/circbuf => github.com/armon/circbuf latest
github.com/armon/go-metrics => github.com/armon/go-metrics latest
Expand Down Expand Up @@ -100,8 +98,6 @@ replace (
github.com/chzyer/logex => github.com/chzyer/logex latest
github.com/chzyer/readline => github.com/chzyer/readline latest
github.com/chzyer/test => github.com/chzyer/test latest
github.com/cilium/ebpf => github.com/cilium/ebpf latest
github.com/circonus-labs/circonus-gometrics => github.com/circonus-labs/circonus-gometrics latest
github.com/cncf/udpa/go => github.com/cncf/udpa/go latest
github.com/cncf/xds/go => github.com/cncf/xds/go latest
github.com/cockroachdb/apd => github.com/cockroachdb/apd latest
Expand Down Expand Up @@ -139,9 +135,6 @@ replace (
github.com/dennwc/varint => github.com/dennwc/varint latest
github.com/devigned/tab => github.com/devigned/tab latest
github.com/dgryski/go-rendezvous => github.com/dgryski/go-rendezvous latest
github.com/dgryski/go-sip13 => github.com/dgryski/go-sip13 latest
github.com/digitalocean/godo => github.com/digitalocean/godo latest
github.com/dimchansky/utfbom => github.com/dimchansky/utfbom latest
github.com/dnaeon/go-vcr => github.com/dnaeon/go-vcr latest
github.com/docker/cli => github.com/docker/cli latest
github.com/docker/distribution => github.com/docker/distribution latest
Expand All @@ -153,22 +146,18 @@ replace (
github.com/docker/go-units => github.com/docker/go-units latest
github.com/docopt/docopt-go => github.com/docopt/docopt-go latest
github.com/dustin/go-humanize => github.com/dustin/go-humanize latest
github.com/dvyukov/go-fuzz => github.com/dvyukov/go-fuzz latest
github.com/edsrzf/mmap-go => github.com/edsrzf/mmap-go latest
github.com/elazarl/goproxy => github.com/elazarl/goproxy latest
github.com/emicklei/go-restful => github.com/emicklei/go-restful latest
github.com/emicklei/go-restful/v3 => github.com/emicklei/go-restful/v3 latest
github.com/envoyproxy/go-control-plane => github.com/envoyproxy/go-control-plane latest
github.com/envoyproxy/protoc-gen-validate => github.com/envoyproxy/protoc-gen-validate latest
github.com/evanphx/json-patch => github.com/evanphx/json-patch latest
github.com/fatih/color => github.com/fatih/color latest
github.com/felixge/httpsnoop => github.com/felixge/httpsnoop latest
github.com/fogleman/gg => github.com/fogleman/gg latest
github.com/form3tech-oss/jwt-go => github.com/form3tech-oss/jwt-go latest
github.com/fortytw2/leaktest => github.com/fortytw2/leaktest latest
github.com/frankban/quicktest => github.com/frankban/quicktest latest
github.com/fsnotify/fsnotify => github.com/fsnotify/fsnotify latest
github.com/ghodss/yaml => github.com/ghodss/yaml latest
github.com/gin-contrib/sse => github.com/gin-contrib/sse latest
github.com/gin-gonic/gin => github.com/gin-gonic/gin latest
github.com/go-errors/errors => github.com/go-errors/errors latest
Expand All @@ -185,8 +174,6 @@ replace (
github.com/go-logr/logr => github.com/go-logr/logr latest
github.com/go-logr/stdr => github.com/go-logr/stdr latest
github.com/go-logr/zapr => github.com/go-logr/zapr latest
github.com/go-openapi/analysis => github.com/go-openapi/analysis latest
github.com/go-openapi/errors => github.com/go-openapi/errors latest
github.com/go-openapi/jsonpointer => github.com/go-openapi/jsonpointer latest
github.com/go-openapi/jsonreference => github.com/go-openapi/jsonreference latest
github.com/go-openapi/loads => github.com/go-openapi/loads latest
Expand Down Expand Up @@ -245,10 +232,6 @@ replace (
github.com/google/uuid => github.com/google/uuid latest
github.com/google/wire => github.com/google/wire latest
github.com/googleapis/gax-go/v2 => github.com/googleapis/gax-go/v2 latest
github.com/googleapis/go-type-adapters => github.com/googleapis/go-type-adapters latest
github.com/gophercloud/gophercloud => github.com/gophercloud/gophercloud latest
github.com/gopherjs/gopherjs => github.com/gopherjs/gopherjs latest
github.com/gorilla/context => github.com/gorilla/context latest
github.com/gorilla/mux => github.com/gorilla/mux latest
github.com/gorilla/websocket => github.com/gorilla/websocket latest
github.com/grafana/regexp => github.com/grafana/regexp latest
Expand Down Expand Up @@ -300,7 +283,6 @@ replace (
github.com/jmespath/go-jmespath/internal/testify => github.com/jmespath/go-jmespath/internal/testify latest
github.com/jmoiron/sqlx => github.com/jmoiron/sqlx latest
github.com/joho/godotenv => github.com/joho/godotenv latest
github.com/jonboulle/clockwork => github.com/jonboulle/clockwork latest
github.com/josharian/intern => github.com/josharian/intern latest
github.com/json-iterator/go => github.com/json-iterator/go latest
github.com/jstemmer/go-junit-report => github.com/jstemmer/go-junit-report latest
Expand Down Expand Up @@ -333,10 +315,6 @@ replace (
github.com/mattn/go-shellwords => github.com/mattn/go-shellwords latest
github.com/mattn/go-sqlite3 => github.com/mattn/go-sqlite3 latest
github.com/matttproud/golang_protobuf_extensions => github.com/matttproud/golang_protobuf_extensions latest
github.com/miekg/dns => github.com/miekg/dns latest
github.com/miekg/pkcs11 => github.com/miekg/pkcs11 latest
github.com/mistifyio/go-zfs => github.com/mistifyio/go-zfs latest
github.com/mitchellh/cli => github.com/mitchellh/cli latest
github.com/mitchellh/colorstring => github.com/mitchellh/colorstring latest
github.com/mitchellh/go-homedir => github.com/mitchellh/go-homedir latest
github.com/mitchellh/go-wordwrap => github.com/mitchellh/go-wordwrap latest
Expand All @@ -355,22 +333,12 @@ replace (
github.com/morikuni/aec => github.com/morikuni/aec latest
github.com/mrunalp/fileutils => github.com/mrunalp/fileutils latest
github.com/munnerz/goautoneg => github.com/munnerz/goautoneg latest
github.com/mwitkow/go-conntrack => github.com/mwitkow/go-conntrack latest
github.com/mxk/go-flowrate => github.com/mxk/go-flowrate latest
github.com/niemeyer/pretty => github.com/niemeyer/pretty latest
github.com/nxadm/tail => github.com/nxadm/tail latest
github.com/oklog/run => github.com/oklog/run latest
github.com/oklog/ulid => github.com/oklog/ulid latest
github.com/onsi/ginkgo => github.com/onsi/ginkgo latest
github.com/onsi/gomega => github.com/onsi/gomega latest
github.com/opencontainers/go-digest => github.com/opencontainers/go-digest latest
github.com/opencontainers/image-spec => github.com/opencontainers/image-spec latest
github.com/opencontainers/runc => github.com/opencontainers/runc latest
github.com/opencontainers/runtime-spec => github.com/opencontainers/runtime-spec latest
github.com/opencontainers/selinux => github.com/opencontainers/selinux latest
github.com/opentracing/opentracing-go => github.com/opentracing/opentracing-go latest
github.com/pascaldekloe/goe => github.com/pascaldekloe/goe latest
github.com/pelletier/go-toml => github.com/pelletier/go-toml latest
github.com/peterbourgon/diskv => github.com/peterbourgon/diskv latest
github.com/phpdave11/gofpdf => github.com/phpdave11/gofpdf latest
github.com/phpdave11/gofpdi => github.com/phpdave11/gofpdi latest
Expand Down Expand Up @@ -426,18 +394,10 @@ replace (
github.com/spf13/cast => github.com/spf13/cast latest
github.com/spf13/cobra => github.com/spf13/cobra latest
github.com/spf13/pflag => github.com/spf13/pflag latest
github.com/stefanberger/go-pkcs11uri => github.com/stefanberger/go-pkcs11uri latest
github.com/stoewer/go-strcase => github.com/stoewer/go-strcase latest
github.com/stretchr/objx => github.com/stretchr/objx latest
github.com/stretchr/testify => github.com/stretchr/testify latest
github.com/syndtr/gocapability => github.com/syndtr/gocapability latest
github.com/tchap/go-patricia => github.com/tchap/go-patricia latest
github.com/tidwall/pretty => github.com/tidwall/pretty latest
github.com/tmc/grpc-websocket-proxy => github.com/tmc/grpc-websocket-proxy latest
github.com/tv42/httpunix => github.com/tv42/httpunix latest
github.com/ugorji/go => github.com/ugorji/go latest
github.com/ugorji/go/codec => github.com/ugorji/go/codec latest
github.com/urfave/cli => github.com/urfave/cli latest
github.com/vdaas/vald-client-go => github.com/vdaas/vald-client-go latest
github.com/vishvananda/netlink => github.com/vishvananda/netlink latest
github.com/vishvananda/netns => github.com/vishvananda/netns latest
Expand All @@ -449,8 +409,6 @@ replace (
github.com/xeipuuv/gojsonschema => github.com/xeipuuv/gojsonschema latest
github.com/xiang90/probing => github.com/xiang90/probing latest
github.com/xlab/treeprint => github.com/xlab/treeprint latest
github.com/youmark/pkcs8 => github.com/youmark/pkcs8 latest
github.com/yuin/goldmark => github.com/yuin/goldmark latest
github.com/zeebo/assert => github.com/zeebo/assert latest
github.com/zeebo/xxh3 => github.com/zeebo/xxh3 latest
go.etcd.io/bbolt => go.etcd.io/bbolt latest
Expand All @@ -464,7 +422,7 @@ replace (
go.mongodb.org/mongo-driver => go.mongodb.org/mongo-driver latest
go.mozilla.org/pkcs7 => go.mozilla.org/pkcs7 latest
go.opencensus.io => go.opencensus.io latest
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc => go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc latest
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc => go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.37.0
go.opentelemetry.io/otel => go.opentelemetry.io/otel v1.11.1
go.opentelemetry.io/otel/exporters/otlp/internal/retry => go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.11.1
go.opentelemetry.io/otel/exporters/otlp/otlpmetric => go.opentelemetry.io/otel/exporters/otlp/otlpmetric v0.33.0
Expand All @@ -482,8 +440,6 @@ replace (
go.uber.org/goleak => go.uber.org/goleak latest
go.uber.org/multierr => go.uber.org/multierr latest
go.uber.org/zap => go.uber.org/zap latest
go4.org/intern => go4.org/intern latest
go4.org/unsafe/assume-no-moving-gc => go4.org/unsafe/assume-no-moving-gc latest
gocloud.dev => gocloud.dev latest
golang.org/x/crypto => golang.org/x/crypto latest
golang.org/x/exp => golang.org/x/exp latest
Expand Down Expand Up @@ -516,17 +472,12 @@ replace (
gopkg.in/gcfg.v1 => gopkg.in/gcfg.v1 latest
gopkg.in/inconshreveable/log15.v2 => gopkg.in/inconshreveable/log15.v2 latest
gopkg.in/inf.v0 => gopkg.in/inf.v0 latest
gopkg.in/ini.v1 => gopkg.in/ini.v1 latest
gopkg.in/natefinch/lumberjack.v2 => gopkg.in/natefinch/lumberjack.v2 latest
gopkg.in/square/go-jose.v2 => gopkg.in/square/go-jose.v2 latest
gopkg.in/telebot.v3 => gopkg.in/telebot.v3 latest
gopkg.in/tomb.v1 => gopkg.in/tomb.v1 latest
gopkg.in/warnings.v0 => gopkg.in/warnings.v0 latest
gopkg.in/yaml.v2 => gopkg.in/yaml.v2 latest
gopkg.in/yaml.v3 => gopkg.in/yaml.v3 latest
gotest.tools/v3 => gotest.tools/v3 latest
honnef.co/go/tools => honnef.co/go/tools latest
inet.af/netaddr => inet.af/netaddr latest
k8s.io/api => k8s.io/api v0.26.0
k8s.io/apiextensions-apiserver => k8s.io/apiextensions-apiserver v0.26.0
k8s.io/apimachinery => k8s.io/apimachinery v0.26.0
Expand Down
21 changes: 16 additions & 5 deletions internal/net/grpc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ func (g *gRPCClient) Range(ctx context.Context,
span.End()
}
}()
g.conns.Range(func(addr string, p pool.Conn) bool {
return g.conns.Range(func(addr string, p pool.Conn) bool {
ssctx, sspan := trace.StartSpan(sctx, apiName+"/Client.Range/"+addr)
defer func() {
if sspan != nil {
Expand All @@ -334,7 +334,6 @@ func (g *gRPCClient) Range(ctx context.Context,
}
return true
})
return nil
}

func (g *gRPCClient) RangeConcurrent(ctx context.Context,
Expand All @@ -348,7 +347,7 @@ func (g *gRPCClient) RangeConcurrent(ctx context.Context,
}()
eg, egctx := errgroup.New(sctx)
eg.Limitation(concurrency)
g.conns.Range(func(addr string, p pool.Conn) bool {
rerr = g.conns.Range(func(addr string, p pool.Conn) bool {
eg.Go(safety.RecoverFunc(func() (err error) {
ssctx, sspan := trace.StartSpan(sctx, apiName+"/Client.RangeConcurrent/"+addr)
defer func() {
Expand All @@ -370,6 +369,9 @@ func (g *gRPCClient) RangeConcurrent(ctx context.Context,
}))
return true
})
if rerr != nil {
return rerr
}
return eg.Wait()
}

Expand All @@ -382,10 +384,13 @@ func (g *gRPCClient) OrderedRange(ctx context.Context,
span.End()
}
}()
if orders == nil {
if len(orders) == 0 {
log.Warn("no order found for OrderedRange")
return g.Range(sctx, f)
}
if g.conns.Len() == 0 {
return errors.ErrGRPCClientConnNotFound("*")
}
for _, addr := range orders {
select {
case <-sctx.Done():
Expand Down Expand Up @@ -422,10 +427,13 @@ func (g *gRPCClient) OrderedRangeConcurrent(ctx context.Context,
span.End()
}
}()
if orders == nil {
if len(orders) == 0 {
log.Warn("no order found for OrderedRangeConcurrent")
return g.RangeConcurrent(sctx, concurrency, f)
}
if g.conns.Len() == 0 {
return errors.ErrGRPCClientConnNotFound("*")
}
eg, egctx := errgroup.New(sctx)
eg.Limitation(concurrency)
for _, order := range orders {
Expand Down Expand Up @@ -468,6 +476,9 @@ func (g *gRPCClient) RoundRobin(ctx context.Context, f func(ctx context.Context,
span.End()
}
}()
if g.conns.Len() == 0 {
return nil, errors.ErrGRPCClientConnNotFound("*")
}
if g.bo != nil && g.atomicAddrs.Len() > 1 {
var boName string
if method := FromGRPCMethod(sctx); len(method) != 0 {
Expand Down
Loading

0 comments on commit e004aae

Please sign in to comment.