From 6b46f470d101e9ad1c8a02a4c8cb06fb53a0d300 Mon Sep 17 00:00:00 2001 From: Doug Fawley Date: Fri, 20 Sep 2019 16:07:23 -0700 Subject: [PATCH] =?UTF-8?q?client:=20consider=20service=20config=20invalid?= =?UTF-8?q?=20if=20loadBalancingConfig=E2=80=A6=20(#3034)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- service_config.go | 8 ++++++++ service_config_test.go | 17 +++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/service_config.go b/service_config.go index d0787f1e2a1c..686ad7ba6160 100644 --- a/service_config.go +++ b/service_config.go @@ -310,6 +310,14 @@ func parseServiceConfig(js string) (*ServiceConfig, error) { } break } + if sc.lbConfig == nil { + // We had a loadBalancingConfig field but did not encounter a + // supported policy. The config is considered invalid in this + // case. + err := fmt.Errorf("invalid loadBalancingConfig: no supported policies found") + grpclog.Warningf(err.Error()) + return nil, err + } } if rsc.MethodConfig == nil { diff --git a/service_config_test.go b/service_config_test.go index 754374bfcc6a..e01e46169f42 100644 --- a/service_config_test.go +++ b/service_config_test.go @@ -92,6 +92,23 @@ func (s) TestParseLBConfig(t *testing.T) { runParseTests(t, testcases) } +func (s) TestParseNoLBConfigSupported(t *testing.T) { + // We have a loadBalancingConfig field but will not encounter a supported + // policy. The config will be considered invalid in this case. + testcases := []parseTestCase{ + { + scjs: `{ + "loadBalancingConfig": [{"not_a_balancer1": {} }, {"not_a_balancer2": {}}] +}`, + wantErr: true, + }, { + scjs: `{"loadBalancingConfig": []}`, + wantErr: true, + }, + } + runParseTests(t, testcases) +} + func (s) TestParseLoadBalancer(t *testing.T) { testcases := []parseTestCase{ {