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:
Anifalak 2024-08-27 21:35:19 +08:00 committed by GitHub
parent ebbbb453be
commit ee4d26b780
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 10 additions and 0 deletions

View file

@ -183,3 +183,11 @@ func (e *Etcd) TTL(kv *mvccpb.KeyValue, serv *msg.Service) uint32 {
func shouldInclude(serv *msg.Service, qType uint16) bool {
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
}

View file

@ -21,6 +21,8 @@ func setup(c *caddy.Controller) error {
return plugin.Error("etcd", err)
}
c.OnShutdown(e.OnShutdown)
dnsserver.GetConfig(c).AddPlugin(func(next plugin.Handler) plugin.Handler {
e.Next = next
return e