xuxueli / xxl-job

A distributed task scheduling framework.(分布式任务调度平台XXL-JOB)
http://www.xuxueli.com/xxl-job/
GNU General Public License v3.0
27.62k stars 10.93k forks source link

0.0.0.0:9999: java.net.BindException: Address already in use #45

Closed zhangqunshi closed 6 years ago

zhangqunshi commented 7 years ago

直接使用新的war覆盖老的war包时出现下面错误日志。同时tomcat也无法正常停止,需要手动kill。

2017-04-20 11:13:29 xxl-job-executor-example [com.mchange.v2.log.MLog]-[MLog-Init-Reporter]-[log]-[212]-[INFO] MLog clients using slf4j logging.
2017-04-20 11:13:30 xxl-job-executor-example [com.mchange.v2.c3p0.C3P0Registry]-[localhost-startStop-1]-[log]-[212]-[INFO] Initializing c3p0-0.9.5.2 [built 08-December-2015 22:06:04 -0800; debug? true; trace: 10]
2017-04-20 11:13:30 xxl-job-executor-example [com.xxl.job.core.executor.XxlJobExecutor]-[localhost-startStop-1]-[registJobHandler]-[109]-[INFO] xxl-job register jobhandler success, name:demoJobHandler, jobHandler:com.xxl.job.executor.service.jobhandler.DemoJobHandler@1a28d110
2017-04-20 11:13:30 xxl-job-executor-example [com.xxl.job.core.executor.XxlJobExecutor]-[localhost-startStop-1]-[registJobHandler]-[109]-[INFO] xxl-job register jobhandler success, name:krisJobHandler, jobHandler:com.xxl.job.executor.service.jobhandler.KrisJobHandler@36bcb2d2
2017-04-20 11:13:30 xxl-job-executor-example [org.springframework.web.context.ContextLoader]-[localhost-startStop-1]-[initWebApplicationContext]-[325]-[INFO] Root WebApplicationContext: initialization completed in 404 ms
2017-04-20 11:13:30 xxl-job-executor-example [org.eclipse.jetty.server.Server]-[Thread-5]-[doStart]-[272]-[INFO] jetty-8.2.0.v20160908
2017-04-20 11:13:30 xxl-job-executor-example [org.eclipse.jetty.util.component.AbstractLifeCycle]-[Thread-5]-[setFailed]-[204]-[WARN] FAILED SelectChannelConnector@0.0.0.0:9999: java.net.BindException: Address already in use
java.net.BindException: Address already in use
    at sun.nio.ch.Net.bind0(Native Method)
    at sun.nio.ch.Net.bind(Net.java:433)
    at sun.nio.ch.Net.bind(Net.java:425)
    at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:223)
    at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74)
    at org.eclipse.jetty.server.nio.SelectChannelConnector.open(SelectChannelConnector.java:187)
    at org.eclipse.jetty.server.AbstractConnector.doStart(AbstractConnector.java:316)
    at org.eclipse.jetty.server.nio.SelectChannelConnector.doStart(SelectChannelConnector.java:265)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
    at org.eclipse.jetty.server.Server.doStart(Server.java:293)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
    at com.xxl.job.core.rpc.netcom.jetty.server.JettyServer$1.run(JettyServer.java:42)
    at java.lang.Thread.run(Thread.java:745)
2017-04-20 11:13:30 xxl-job-executor-example [org.eclipse.jetty.util.component.AbstractLifeCycle]-[Thread-5]-[setFailed]-[204]-[WARN] FAILED org.eclipse.jetty.server.Server@368659c1: java.net.BindException: Address already in use
java.net.BindException: Address already in use
    at sun.nio.ch.Net.bind0(Native Method)
    at sun.nio.ch.Net.bind(Net.java:433)
    at sun.nio.ch.Net.bind(Net.java:425)
    at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:223)
    at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74)
    at org.eclipse.jetty.server.nio.SelectChannelConnector.open(SelectChannelConnector.java:187)
    at org.eclipse.jetty.server.AbstractConnector.doStart(AbstractConnector.java:316)
    at org.eclipse.jetty.server.nio.SelectChannelConnector.doStart(SelectChannelConnector.java:265)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
    at org.eclipse.jetty.server.Server.doStart(Server.java:293)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
    at com.xxl.job.core.rpc.netcom.jetty.server.JettyServer$1.run(JettyServer.java:42)
    at java.lang.Thread.run(Thread.java:745)
2017-04-20 11:13:30 xxl-job-executor-example [com.xxl.job.core.rpc.netcom.jetty.server.JettyServer]-[Thread-5]-[run]-[48]-[ERROR] 
java.net.BindException: Address already in use
    at sun.nio.ch.Net.bind0(Native Method)
    at sun.nio.ch.Net.bind(Net.java:433)
    at sun.nio.ch.Net.bind(Net.java:425)
    at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:223)
    at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74)
    at org.eclipse.jetty.server.nio.SelectChannelConnector.open(SelectChannelConnector.java:187)
    at org.eclipse.jetty.server.AbstractConnector.doStart(AbstractConnector.java:316)
    at org.eclipse.jetty.server.nio.SelectChannelConnector.doStart(SelectChannelConnector.java:265)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
    at org.eclipse.jetty.server.Server.doStart(Server.java:293)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
    at com.xxl.job.core.rpc.netcom.jetty.server.JettyServer$1.run(JettyServer.java:42)
    at java.lang.Thread.run(Thread.java:745)
2017-04-20 11:13:45 xxl-job-executor-example [org.springframework.web.context.support.XmlWebApplicationContext]-[localhost-startStop-2]-[doClose]-[1048]-[INFO] Closing Root WebApplicationContext: startup date [Thu Apr 20 11:13:29 CST 2017]; root of context hierarchy
2017-04-20 11:13:45 xxl-job-executor-example [org.springframework.beans.factory.support.DefaultListableBeanFactory]-[localhost-startStop-2]-[destroySingletons]-[444]-[INFO] Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@7b84b764: defining beans [propertyConfigurer,demoJobHandler,krisJobHandler,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,xxlJobExecutor,glueFactory,xxlJobDataSource,org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor]; root of factory hierarchy
2017-04-20 11:13:45 xxl-job-executor-example [com.xxl.job.core.rpc.netcom.jetty.server.JettyServer]-[localhost-startStop-2]-[destroy]-[63]-[ERROR] 
java.lang.IllegalStateException: !STOPPED
    at org.eclipse.jetty.server.handler.HandlerWrapper.destroy(HandlerWrapper.java:172)
    at com.xxl.job.core.rpc.netcom.jetty.server.JettyServer.destroy(JettyServer.java:61)
    at com.xxl.job.core.rpc.netcom.NetComServerFactory.destroy(NetComServerFactory.java:31)
    at com.xxl.job.core.executor.XxlJobExecutor.destroy(XxlJobExecutor.java:60)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.springframework.beans.factory.support.DisposableBeanAdapter.invokeCustomDestroyMethod(DisposableBeanAdapter.java:328)
    at org.springframework.beans.factory.support.DisposableBeanAdapter.destroy(DisposableBeanAdapter.java:254)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroyBean(DefaultSingletonBeanRegistry.java:510)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingleton(DefaultSingletonBeanRegistry.java:486)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.destroySingleton(DefaultListableBeanFactory.java:751)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingletons(DefaultSingletonBeanRegistry.java:455)
    at org.springframework.context.support.AbstractApplicationContext.destroyBeans(AbstractApplicationContext.java:1096)
    at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:1070)
    at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:1016)
    at org.springframework.web.context.ContextLoader.closeWebApplicationContext(ContextLoader.java:586)
    at org.springframework.web.context.ContextLoaderListener.contextDestroyed(ContextLoaderListener.java:143)
    at org.apache.catalina.core.StandardContext.listenerStop(StandardContext.java:4792)
    at org.apache.catalina.core.StandardContext.stopInternal(StandardContext.java:5429)
    at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:226)
    at org.apache.catalina.core.ContainerBase$StopChild.call(ContainerBase.java:1435)
    at org.apache.catalina.core.ContainerBase$StopChild.call(ContainerBase.java:1424)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
2017-04-20 11:13:45 xxl-job-executor-example [com.xxl.job.core.rpc.netcom.jetty.server.JettyServer]-[localhost-startStop-2]-[destroy]-[69]-[INFO] >>>>>>>>>>> xxl-rpc server destroy success, netcon=com.xxl.job.core.rpc.netcom.jetty.server.JettyServer
2017-04-20 11:14:06 xxl-job-executor-example [org.springframework.web.context.ContextLoader]-[localhost-startStop-1]-[initWebApplicationContext]-[285]-[INFO] Root WebApplicationContext: initialization started
2017-04-20 11:14:06 xxl-job-executor-example [org.springframework.web.context.support.XmlWebApplicationContext]-[localhost-startStop-1]-[prepareRefresh]-[515]-[INFO] Refreshing Root WebApplicationContext: startup date [Thu Apr 20 11:14:06 CST 2017]; root of context hierarchy
xuxueli commented 7 years ago

应该是执行器端口被占用,可以确认下对应端口占用情况。然后重新部署,启动执行器啊!

zhangqunshi commented 7 years ago

个人感觉这个端口占用,是由于之前部署的程序没有能够正常停止。所以需要先查查如何在重新部署war的时候正确停止jetty.

xuxueli commented 7 years ago

执行器Bean销毁的时候,主动destory了jetty服务,但是还是偶尔出现无法销毁的情况,头大!

dxjaccp commented 7 years ago

JettyServer的方法好像有点问题。start加个同步。destroy方法里面server.destroy改成server.stop()

xuxueli commented 7 years ago

非常感谢 “@dxjaccp ”,这个问题已经修复啦!确实是因为JettyServer的destory逻辑存在瑕疵,master分支已经修复可以参考(com.xxl.job.core.rpc.netcom.jetty.server.JettyServer#destroy)进行修改,也可以直接pull下来master分支体验。

xuxueli commented 7 years ago

@dxjaccp 你好,你所说的 “start加个同步” 应该怎么理解呢 :)

liuhang93 commented 7 years ago

at com.xxl.job.core.rpc.netcom.jetty.server.JettyServer$1.run(JettyServer.java:43); 重新部署时,jetty 好像依旧不能正常启动,端口占用。第一次部署不报这个错

xuxueli commented 6 years ago

@husthang jetty会占用通讯端口,在停止执行器时需要一同销毁。比如在调用 Tomcat 的shutdown脚本,将会自动释放相关端口。