zeromicro / go-zero

A cloud-native Go microservices framework with cli tool for productivity.
https://go-zero.dev
MIT License
28.89k stars 3.91k forks source link

program exit, if registry use etcd, client must unregistry etcd before program exit #4271

Open Owen-Zhang opened 1 month ago

Owen-Zhang commented 1 month ago

如果使用etcd注册服务, 在程序退出前,应该主动unregistry etcd(取消服务注册),不应该等etcd center 租约超时

publisher.go -> doKeepAlive() 

// 多处使用这种方式,导制退出没有取消服务注册
case <-p.quit.Done():
    return nil

// 可以增加一个服务反注册,取rpc注册服务更合理,同时client也可以更早的发现某个服务下线
kevwan commented 2 weeks ago

Check the code here.

https://github.com/zeromicro/go-zero/blob/896e1a2abb09254ec37952869e40b2eeee5f0200/core/discov/publisher.go#L149