zeromicro / go-zero

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

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

Open Owen-Zhang opened 4 months ago

Owen-Zhang commented 4 months ago

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

publisher.go -> doKeepAlive() 

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

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

Check the code here.

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