Skip to content

Conversation

huicunjun
Copy link
Contributor

遇到的问题

发版期间,springboot 是先拒绝请求,再下线nacos注册的实例,导致gateway有部分流量打到服务,服务会拒绝请求

@PreDestroy public void destroy() { stop(); }

这是目前的关机逻辑,这个钩子会在springweb拒绝请求后再执行

解决办法

springboot 下有SpringApplicationShutdownHook,会比PreDestroy回调更早,并且回调hook事件期间springweb 依然可以正常处理请求,我们可以在下线nacos后,休眠10s时间吞吐掉网关转发来的请求(拿到上一个已下线节点的请求),

目前生产环境测试发版不会抖动

@CLAassistant
Copy link

CLAassistant commented Mar 28, 2025

CLA assistant check
All committers have signed the CLA.

@yuluo-yx
Copy link
Collaborator

单测失败了,可以修复下?

@huicunjun
Copy link
Contributor Author

单测失败了,可以修复下?

看样子是cicd下载依赖出问题了?

@yuluo-yx
Copy link
Collaborator

单测失败了,可以修复下?

看样子是cicd下载依赖出问题了?

ok, 我来重试下

@yuluo-yx
Copy link
Collaborator

单测失败了,可以修复下?

看样子是cicd下载依赖出问题了?

看样子是 action/cache 失败了,但是很奇怪,为什么失败了?👀👀

@huicunjun
Copy link
Contributor Author

单测失败了,可以修复下?

看样子是cicd下载依赖出问题了?

看样子是 action/cache 失败了,但是很奇怪,为什么失败了?👀👀
image

下不动这个版本,查了下推荐使用actions/cache@v3了,敢改这个吗

@yuluo-yx
Copy link
Collaborator

下不动这个版本,查了下推荐使用actions/cache@v3了,敢改这个吗

可以改的,最新版本似乎是 v4, https://github.com/actions/cache

@huicunjun huicunjun closed this May 8, 2025
@huicunjun
Copy link
Contributor Author

下不动这个版本,查了下推荐使用actions/cache@v3了,敢改这个吗

可以改的,最新版本似乎是 v4, https://github.com/actions/cache

我对着文档,尝试升级了这个以及相关依赖,不知道能不能解决问题,已提交代码了

https://github.com/actions/checkout https://github.com/actions/setup-java

@huicunjun huicunjun reopened this May 8, 2025
@huicunjun
Copy link
Contributor Author

@yuluo-yx
可以再构建一下吗

Copy link
Collaborator

@yuluo-yx yuluo-yx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks

@yuluo-yx yuluo-yx merged commit ae82b71 into alibaba:2023.x May 8, 2025
3 checks passed
NewGr8Player pushed a commit to NewGr8Player/spring-cloud-alibaba that referenced this pull request May 12, 2025
@axeon
Copy link

axeon commented Jun 12, 2025

遇到的问题

发版期间,springboot 是先拒绝请求,再下线nacos注册的实例,导致gateway有部分流量打到服务,服务会拒绝请求

@PreDestroy public void destroy() { stop(); }

这是目前的关机逻辑,这个钩子会在springweb拒绝请求后再执行

解决办法

springboot 下有SpringApplicationShutdownHook,会比PreDestroy回调更早,并且回调hook事件期间springweb 依然可以正常处理请求,我们可以在下线nacos后,休眠10s时间吞吐掉网关转发来的请求(拿到上一个已下线节点的请求),

目前生产环境测试发版不会抖动

	@EventListener(ContextClosedEvent.class)
	public void onContextClosedEvent(ContextClosedEvent event) {
		NacosDiscoveryProperties configuration = (NacosDiscoveryProperties) getConfiguration();
		Integer gracefulShutdownWaitTime = configuration.getGracefulShutdownWaitTime();
		ThreadUtils.sleep(gracefulShutdownWaitTime);
        stop();
	}

请问一下,为什么sleep在stop()之前?
如果closeEvent之后,第一时间stop()不是更好么?

@axeon
Copy link

axeon commented Jun 13, 2025

遇到的问题

发版期间,springboot 是先拒绝请求,再下线nacos注册的实例,导致gateway有部分流量打到服务,服务会拒绝请求
@PreDestroy public void destroy() { stop(); }
这是目前的关机逻辑,这个钩子会在springweb拒绝请求后再执行

解决办法

springboot 下有SpringApplicationShutdownHook,会比PreDestroy回调更早,并且回调hook事件期间springweb 依然可以正常处理请求,我们可以在下线nacos后,休眠10s时间吞吐掉网关转发来的请求(拿到上一个已下线节点的请求),

目前生产环境测试发版不会抖动

	@EventListener(ContextClosedEvent.class)
	public void onContextClosedEvent(ContextClosedEvent event) {
		NacosDiscoveryProperties configuration = (NacosDiscoveryProperties) getConfiguration();
		Integer gracefulShutdownWaitTime = configuration.getGracefulShutdownWaitTime();
		ThreadUtils.sleep(gracefulShutdownWaitTime);
        stop();
	}

请问一下,为什么sleep在stop()之前? 如果closeEvent之后,第一时间stop()不是更好么?

经过测试,这段代码might be写错了。
stop应该在sleep之前,才是正确的逻辑。

KouShenhai added a commit to KouShenhai/KCloud-Platform-IoT that referenced this pull request Sep 2, 2025
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

Successfully merging this pull request may close these issues.

4 participants