Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Instances that do not go offline and stop in time within the heartbeat detection period #12707

Open
xiaolianghu opened this issue Oct 1, 2024 · 1 comment

Comments

@xiaolianghu
Copy link

心跳检测周期内,未及时下线停止的实例

Nacos currently supports temporary instances to maintain activity by heartbeat reporting. The default interval for sending a heartbeat is 5 seconds. Nacos server will set the instance as unhealthy after 15 seconds without receiving a heartbeat, and remove the temporary instance after 30 seconds without receiving a heartbeat.
If the current instance has been stopped but is within the heartbeat detection cycle, nacos returns the stopped instance, causing an error.Is there any way to avoid it?

Nacos 目前支持临时实例使用心跳上报方式维持活性,发送心跳的周期默认是 5 秒,Nacos 服务端会在 15 秒没收到心跳后将实例设置为不健康,在 30 秒没收到心跳时将这个临时实例摘除。
如果当前实例已经停止,但是刚好处于心跳检测周期内,那么nacos会返回这个已停止的实例,导致错误。有什么办法可以避免吗?

@shengbinxu
Copy link
Contributor

这个问题,主要涉及到jvm shutdown hookspring 优雅停机等相关知识。
我写了个demo(参考项目中readme),来演示“如何在基于nacos做服务发现的微服务项目中实现优雅停止”

https://github.com/shengbinxu/GracefulShutdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants