plugin/etcd: fix etcd connection leakage when reload (#6646)
Signed-off-by: zhongyuanjun <zhongyuanjun@bytedance.com> Co-authored-by: zhongyuanjun <zhongyuanjun@bytedance.com>
This commit is contained in:
parent
ebbbb453be
commit
ee4d26b780
2 changed files with 10 additions and 0 deletions
|
@ -183,3 +183,11 @@ func (e *Etcd) TTL(kv *mvccpb.KeyValue, serv *msg.Service) uint32 {
|
||||||
func shouldInclude(serv *msg.Service, qType uint16) bool {
|
func shouldInclude(serv *msg.Service, qType uint16) bool {
|
||||||
return (qType == dns.TypeTXT && serv.Text != "") || serv.Host != ""
|
return (qType == dns.TypeTXT && serv.Text != "") || serv.Host != ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// OnShutdown shuts down etcd client when caddy instance restart
|
||||||
|
func (e *Etcd) OnShutdown() error {
|
||||||
|
if e.Client != nil {
|
||||||
|
e.Client.Close()
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
|
@ -21,6 +21,8 @@ func setup(c *caddy.Controller) error {
|
||||||
return plugin.Error("etcd", err)
|
return plugin.Error("etcd", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
c.OnShutdown(e.OnShutdown)
|
||||||
|
|
||||||
dnsserver.GetConfig(c).AddPlugin(func(next plugin.Handler) plugin.Handler {
|
dnsserver.GetConfig(c).AddPlugin(func(next plugin.Handler) plugin.Handler {
|
||||||
e.Next = next
|
e.Next = next
|
||||||
return e
|
return e
|
||||||
|
|
Loading…
Add table
Reference in a new issue