Fix a test failure I observed on ent re cluster listener (#8647)

Panics when the cluster listener changes while we're setting up request forwarding.
This commit is contained in:
ncabatoff 2020-03-31 13:47:39 -04:00 committed by GitHub
parent 015114f61e
commit 236eb7e19f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -200,7 +200,8 @@ func (c *Core) startForwarding(ctx context.Context) error {
c.clearForwardingClients()
c.requestForwardingConnectionLock.Unlock()
if c.ha == nil || c.getClusterListener() == nil {
clusterListener := c.getClusterListener()
if c.ha == nil || clusterListener == nil {
c.logger.Debug("request forwarding not setup")
return nil
}
@ -210,20 +211,21 @@ func (c *Core) startForwarding(ctx context.Context) error {
return err
}
handler, err := NewRequestForwardingHandler(c, c.getClusterListener().Server(), perfStandbySlots, perfStandbyRepCluster)
handler, err := NewRequestForwardingHandler(c, clusterListener.Server(), perfStandbySlots, perfStandbyRepCluster)
if err != nil {
return err
}
c.getClusterListener().AddHandler(consts.RequestForwardingALPN, handler)
clusterListener.AddHandler(consts.RequestForwardingALPN, handler)
return nil
}
func (c *Core) stopForwarding() {
if c.getClusterListener() != nil {
c.getClusterListener().StopHandler(consts.RequestForwardingALPN)
c.getClusterListener().StopHandler(consts.PerfStandbyALPN)
clusterListener := c.getClusterListener()
if clusterListener != nil {
clusterListener.StopHandler(consts.RequestForwardingALPN)
clusterListener.StopHandler(consts.PerfStandbyALPN)
}
c.removeAllPerfStandbySecondaries()
}