xds: fix eds balancer nil pointer panic without addresses (#2809)

This commit is contained in:
Menghan Li
2019-05-28 11:14:10 -07:00
committed by GitHub
parent f34abd9513
commit b3e4b49ddb
2 changed files with 10 additions and 1 deletions

View File

@ -277,7 +277,9 @@ func (xdsB *EDSBalancer) UpdateBalancerState(s connectivity.State, p balancer.Pi
// Close closes the balancer.
func (xdsB *EDSBalancer) Close() {
xdsB.bg.close()
if xdsB.bg != nil {
xdsB.bg.close()
}
}
type dropPicker struct {

View File

@ -337,6 +337,13 @@ func TestEDS_TwoLocalities(t *testing.T) {
}
}
func TestClose(t *testing.T) {
edsb := NewXDSBalancer(nil, nil)
// This is what could happen when switching between fallback and eds. This
// make sure it doesn't panic.
edsb.Close()
}
func init() {
balancer.Register(&testConstBalancerBuilder{})
}