Skip to content

Commit 6b46f47

Browse files
authored
client: consider service config invalid if loadBalancingConfig… (#3034)
1 parent a5e64ec commit 6b46f47

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

Diff for: service_config.go

+8
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,14 @@ func parseServiceConfig(js string) (*ServiceConfig, error) {
310310
}
311311
break
312312
}
313+
if sc.lbConfig == nil {
314+
// We had a loadBalancingConfig field but did not encounter a
315+
// supported policy. The config is considered invalid in this
316+
// case.
317+
err := fmt.Errorf("invalid loadBalancingConfig: no supported policies found")
318+
grpclog.Warningf(err.Error())
319+
return nil, err
320+
}
313321
}
314322

315323
if rsc.MethodConfig == nil {

Diff for: service_config_test.go

+17
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,23 @@ func (s) TestParseLBConfig(t *testing.T) {
9292
runParseTests(t, testcases)
9393
}
9494

95+
func (s) TestParseNoLBConfigSupported(t *testing.T) {
96+
// We have a loadBalancingConfig field but will not encounter a supported
97+
// policy. The config will be considered invalid in this case.
98+
testcases := []parseTestCase{
99+
{
100+
scjs: `{
101+
"loadBalancingConfig": [{"not_a_balancer1": {} }, {"not_a_balancer2": {}}]
102+
}`,
103+
wantErr: true,
104+
}, {
105+
scjs: `{"loadBalancingConfig": []}`,
106+
wantErr: true,
107+
},
108+
}
109+
runParseTests(t, testcases)
110+
}
111+
95112
func (s) TestParseLoadBalancer(t *testing.T) {
96113
testcases := []parseTestCase{
97114
{

0 commit comments

Comments
 (0)