Skip to content
Snippets Groups Projects
Unverified Commit 8456fb6f authored by zhang siyu's avatar zhang siyu Committed by GitHub
Browse files

bugfix: fix ApplicationContext already closed problem when Seata server using...

bugfix: fix ApplicationContext already closed problem when Seata server using ShutdownHook to destroy. (#4032)
parent 8fd705b9
No related branches found
No related tags found
No related merge requests found
......@@ -63,6 +63,7 @@ Seata 是一款开源的分布式事务解决方案,提供高性能和简单
- [[#3998](https://github.com/seata/seata/pull/3998)] 修复 jedis multi.exec 的 NPE 问题
- [[#4011](https://github.com/seata/seata/pull/4011)] 修复 springboot下无法获取distributed-lock-table配置
- [[#4023](https://github.com/seata/seata/pull/4023)] 修复 dubbo部分场景存在xid未清除的问题
- [[#4032](https://github.com/seata/seata/pull/4032)] 修复server端的ShutdownHook在资源释放时,ApplicationContext已关闭的问题
- [[#4039](https://github.com/seata/seata/pull/4039)] 修复 本地事务抛出异常之后,RM没有清除xid
......@@ -152,7 +153,7 @@ Seata 是一款开源的分布式事务解决方案,提供高性能和简单
- [elrond-g](https://github.com/elrond-g)
- [Rubbernecker](https://github.com/Rubbernecker)
- [zhixing](https://github.com/chenlei3641)
- [siyu](https://github.com/Pinocchio2018)
同时,我们收到了社区反馈的很多有价值的issue和建议,非常感谢大家。
......
......@@ -62,7 +62,7 @@
- [[#4011](https://github.com/seata/seata/pull/4011)] fix can not get properties of distributed-lock-table in springboot
- [[#4023](https://github.com/seata/seata/pull/4023)] fix the problem that the xid is not cleared in some scenes of dubbo
- [[#4039](https://github.com/seata/seata/pull/4039)] fix RM did not clear XID after the local transaction threw an exception
- [[#4032](https://github.com/seata/seata/pull/4032)] fix ApplicationContext already closed problem when Seata server using ShutdownHook to destroy
### optimize:
- [[#3678](https://github.com/seata/seata/pull/3678)] supplement missing configuration and new version documents
......@@ -151,6 +151,7 @@
- [lvekee](https://github.com/lvekee)
- [elrond-g](https://github.com/elrond-g)
- [zhixing](https://github.com/chenlei3641)
- [siyu](https://github.com/Pinocchio2018)
Also, we receive many valuable issues, questions and advices from our community. Thanks for you all.
......
......@@ -25,7 +25,6 @@ import io.seata.common.util.NetUtil;
import io.seata.common.util.StringUtils;
import io.seata.config.ConfigurationFactory;
import io.seata.core.constants.ConfigurationKeys;
import io.seata.core.rpc.ShutdownHook;
import io.seata.core.rpc.netty.NettyRemotingServer;
import io.seata.core.rpc.netty.NettyServerConfig;
import io.seata.server.coordinator.DefaultCoordinator;
......@@ -80,9 +79,10 @@ public class Server {
DefaultCoordinator coordinator = DefaultCoordinator.getInstance(nettyRemotingServer);
coordinator.init();
nettyRemotingServer.setHandler(coordinator);
// register ShutdownHook
ShutdownHook.getInstance().addDisposable(coordinator);
ShutdownHook.getInstance().addDisposable(nettyRemotingServer);
// let ServerRunner do destroy instead ShutdownHook, see https://github.com/seata/seata/issues/4028
ServerRunner.addDisposable(coordinator);
ServerRunner.addDisposable(nettyRemotingServer);
//127.0.0.1 and 0.0.0.0 are not valid here.
if (NetUtil.isValidIp(parameterParser.getHost(), false)) {
......
......@@ -28,6 +28,5 @@ public class ServerApplication {
public static void main(String[] args) throws IOException {
// run the spring-boot application
SpringApplication.run(ServerApplication.class, args);
}
}
......@@ -15,21 +15,33 @@
*/
package io.seata.server;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import io.seata.core.rpc.Disposable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
/**
* @author spilledyear@outlook.com
*/
@Component
public class ServerRunner implements CommandLineRunner {
public class ServerRunner implements CommandLineRunner, DisposableBean {
private static final Logger LOGGER = LoggerFactory.getLogger(ServerRunner.class);
private boolean started = Boolean.FALSE;
private static final List<Disposable> DISPOSABLE_LIST = new CopyOnWriteArrayList<>();
public static void addDisposable(Disposable disposable) {
DISPOSABLE_LIST.add(disposable);
}
@Override
public void run(String... args) {
......@@ -51,4 +63,20 @@ public class ServerRunner implements CommandLineRunner {
public boolean started() {
return started;
}
@Override
public void destroy() throws Exception {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("destoryAll starting");
}
for (Disposable disposable : DISPOSABLE_LIST) {
disposable.destroy();
}
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("destoryAll finish");
}
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment