weibocom / motan

A cross-language remote procedure call(RPC) framework for rapid development of high performance distributed services.
Other
5.9k stars 1.78k forks source link

web项目调用rpc接口后,在停止tomcat的时候,停不下来,必须kill才行,怎么破? #420

Open 89333367 opened 7 years ago

89333367 commented 7 years ago
25-Apr-2017 15:04:08.220 严重 [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [uml-web-api-bigdata-impl] created a ThreadLocal with key of type [com.weibo.api.motan.rpc.RpcContext$1] (value [com.weibo.api.motan.rpc.RpcContext$1@174831bd]) and a value of type [com.weibo.api.motan.rpc.RpcContext] (value [com.weibo.api.motan.rpc.RpcContext@5d64e6e9]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
25-Apr-2017 15:04:08.220 严重 [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [uml-web-api-bigdata-impl] created a ThreadLocal with key of type [com.weibo.api.motan.cluster.ha.FailoverHaStrategy$1] (value [com.weibo.api.motan.cluster.ha.FailoverHaStrategy$1@3e0b2dd1]) and a value of type [java.util.ArrayList] (value [[com.weibo.api.motan.protocol.rpc.DefaultRpcProtocol$DefaultRpcReferer@68182674]]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
25-Apr-2017 15:04:08.222 信息 [main] org.apache.coyote.AbstractProtocol.stop Stopping ProtocolHandler ["http-nio-8080"]
25-Apr-2017 15:04:08.224 信息 [main] org.apache.coyote.AbstractProtocol.stop Stopping ProtocolHandler ["ajp-nio-8009"]
25-Apr-2017 15:04:08.225 信息 [main] org.apache.coyote.AbstractProtocol.destroy Destroying ProtocolHandler ["http-nio-8080"]
25-Apr-2017 15:04:08.226 信息 [main] org.apache.coyote.AbstractProtocol.destroy Destroying ProtocolHandler ["ajp-nio-8009"]
rayzhang0603 commented 7 years ago

感谢反馈。问题的原因见https://github.com/weibocom/motan/issues/79 我们准备通过ShutdownHook的方式fix这个问题,近期会发布一个小版本,请关注。

yanminmin commented 7 years ago

有相关的分支吗?

yanminmin commented 7 years ago

@rayzhang0603 大神

rayzhang0603 commented 7 years ago

@yanminmin 现在还没有,尽量下周提交一个分支

yanminmin commented 7 years ago

多谢,非常期待.能透露下解决方案吗?

rayzhang0603 commented 7 years ago

@yanminmin @89333367 motan0.3.1版本已提供了com.weibo.api.motan.closable.ShutDownHookListener,在web.xml中添加ShutDownHookListener即可

89333367 commented 7 years ago

加上了,这样加的,但是还是报错,而且tomcat没有关掉,还是要kill

    <listener>
        <listener-class>com.weibo.api.motan.closable.ShutDownHookListener</listener-class>
    </listener>
13-Jul-2017 11:25:01.341 严重 [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [uml-web-api-bigdata-impl] created a ThreadLocal with key of type [com.weibo.api.motan.cluster.ha.FailoverHaStrategy$1] (value [com.weibo.api.motan.cluster.ha.FailoverHaStrategy$1@23a56183]) and a value of type [java.util.ArrayList] (value [[com.weibo.api.motan.protocol.rpc.DefaultRpcProtocol$DefaultRpcReferer@36e8d839]]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
13-Jul-2017 11:25:01.341 严重 [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [uml-web-api-bigdata-impl] created a ThreadLocal with key of type [com.weibo.api.motan.rpc.RpcContext$1] (value [com.weibo.api.motan.rpc.RpcContext$1@1458685b]) and a value of type [com.weibo.api.motan.rpc.RpcContext] (value [com.weibo.api.motan.rpc.RpcContext@735f15a6]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
13-Jul-2017 11:25:01.341 严重 [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [uml-web-api-bigdata-impl] created a ThreadLocal with key of type [com.weibo.api.motan.cluster.ha.FailoverHaStrategy$1] (value [com.weibo.api.motan.cluster.ha.FailoverHaStrategy$1@23a56183]) and a value of type [java.util.ArrayList] (value [[com.weibo.api.motan.protocol.rpc.DefaultRpcProtocol$DefaultRpcReferer@36e8d839]]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
13-Jul-2017 11:25:01.341 严重 [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [uml-web-api-bigdata-impl] created a ThreadLocal with key of type [com.weibo.api.motan.rpc.RpcContext$1] (value [com.weibo.api.motan.rpc.RpcContext$1@1458685b]) and a value of type [com.weibo.api.motan.rpc.RpcContext] (value [com.weibo.api.motan.rpc.RpcContext@5cea56ee]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
13-Jul-2017 11:25:01.342 严重 [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [uml-web-api-bigdata-impl] created a ThreadLocal with key of type [com.weibo.api.motan.cluster.ha.FailoverHaStrategy$1] (value [com.weibo.api.motan.cluster.ha.FailoverHaStrategy$1@23a56183]) and a value of type [java.util.ArrayList] (value [[com.weibo.api.motan.protocol.rpc.DefaultRpcProtocol$DefaultRpcReferer@36e8d839]]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
13-Jul-2017 11:25:01.342 严重 [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [uml-web-api-bigdata-impl] created a ThreadLocal with key of type [com.weibo.api.motan.rpc.RpcContext$1] (value [com.weibo.api.motan.rpc.RpcContext$1@1458685b]) and a value of type [com.weibo.api.motan.rpc.RpcContext] (value [com.weibo.api.motan.rpc.RpcContext@57139af0]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
13-Jul-2017 11:25:01.342 严重 [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [uml-web-api-bigdata-impl] created a ThreadLocal with key of type [com.weibo.api.motan.cluster.ha.FailoverHaStrategy$1] (value [com.weibo.api.motan.cluster.ha.FailoverHaStrategy$1@23a56183]) and a value of type [java.util.ArrayList] (value [[com.weibo.api.motan.protocol.rpc.DefaultRpcProtocol$DefaultRpcReferer@36e8d839]]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
13-Jul-2017 11:25:01.343 严重 [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [uml-web-api-bigdata-impl] created a ThreadLocal with key of type [com.weibo.api.motan.rpc.RpcContext$1] (value [com.weibo.api.motan.rpc.RpcContext$1@1458685b]) and a value of type [com.weibo.api.motan.rpc.RpcContext] (value [com.weibo.api.motan.rpc.RpcContext@5a394446]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
rayzhang0603 commented 7 years ago

看这个异常应该是tomcat启动就没有成功吧,查一查tomcat启动失败的具体原因

89333367 commented 7 years ago

启动是成功的,并且页面还可以通过RPC查询出结果。

rayzhang0603 commented 7 years ago

可以确认一下info日志中是否有如下关键字Start to close global resource due to priority 如果没有表示ShutDownHookListener并没有执行 可以参考这部分代码的日志,看看静态资源回收的情况

private synchronized void closeAll() {
    Collections.sort(resourceList);
    LoggerUtil.info("Start to close global resource due to priority");
    for (closableObject resource : resourceList) {
        try {
            resource.closable.close();
        } catch (Exception e) {
            LoggerUtil.error("Failed to close " + resource.closable.getClass(), e);
        }
        LoggerUtil.info("Success to close " + resource.closable.getClass());
    }
    LoggerUtil.info("Success to close all the resource!");
    resourceList.clear();
}
89333367 commented 7 years ago

嗯,确实没有这句话。 但是

 <listener>
        <listener-class>com.weibo.api.motan.closable.ShutDownHookListener</listener-class>
    </listener>

已经添加了,还有别的配置么?

rayzhang0603 commented 7 years ago

不需要别的什么配置,ShutDownHookListener实现了javax.servlet.ServletContextListener,只要能够正确加载就应该可以