问题描述
有两台linux服务器A、B系统版本都是 Red Hat Enterprise Linux Server release 6.0 (Santiago)JDK版本都是 1.6.0_29在A端发布一个RMI服务,配置如下<bean id="rmiServerHost" factory-method="setProperty" class="java.lang.System" lazy-init="false"> <constructor-arg value="java.rmi.server.hostname"/> <constructor-arg value="${rmiServerHost}"/> </bean> <bean factory-method="setProperty" class="java.lang.System" lazy-init="false"> <constructor-arg value="java.rmi.dgc.leaseValue"/> <constructor-arg value="300000"/> </bean> <bean factory-method="setProperty" class="java.lang.System" lazy-init="false"> <constructor-arg value="java.rmi.dgc.gcInterval"/> <constructor-arg value="900000"/> </bean> <!--接收数据服务(下层模块提交的数据)--> <bean id="eventProcessor" class="com.dataservice.EventProcessorImpl"/> <bean id="rmiEventProcess" class="org.springframework.remoting.rmi.RmiServiceExporter"> <property name="serviceName" value="dataservice/eventProcessor" /> <property name="service" ref="eventProcessor" /> <property name="serviceInterface" value="com.dataservice.EventProcessor" /> <property name="registryPort" value="${registryPort}"/> <property name="servicePort" value="${registryPort}"/> </bean>B端为客户端,配置如下<!--目标模块数据处理配置--> <bean id="rmiEventProcessorClient" class="org.springframework.remoting.rmi.RmiProxyFactoryBean"><property name="serviceUrl" value="${targetAddr}" /><property name="serviceInterface"value="com.dataservice.EventProcessor" /><property name="refreshStubOnConnectFailure" value="true"></property></bean>情况是这样的,B端在调用A端发布的服务时,间歇性的出现如下异常。异常信息:error marshalling arguments; nested exception is: java.net.SocketException: Broken pipejava.rmi.MarshalException: error marshalling arguments; nested exception is: java.net.SocketException: Broken pipe at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:138) at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(RemoteObjectInvocationHandler.java:178) at java.rmi.server.RemoteObjectInvocationHandler.invoke(RemoteObjectInvocationHandler.java:132) at $Proxy0.invoke(Unknown Source) at org.springframework.remoting.rmi.RmiClientInterceptor.doInvoke(RmiClientInterceptor.java:398) at org.springframework.remoting.rmi.RmiClientInterceptor.doInvoke(RmiClientInterceptor.java:344) at org.springframework.remoting.rmi.RmiClientInterceptor.invoke(RmiClientInterceptor.java:259) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202) at $Proxy1.handleEvent(Unknown Source) at com.dataservice.EventSenderImpl.handleEvent(EventSenderImpl.java:220) at com.dataservice.EventSenderImpl.sendEventTask(EventSenderImpl.java:191) at com.dataservice.EventSenderImpl.access$0(EventSenderImpl.java:173) at com.dataservice.EventSenderImpl$ResSendTask.run(EventSenderImpl.java:166) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441) at java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:317) at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:150) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$101(ScheduledThreadPoolExecutor.java:98) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.runPeriodic(ScheduledThreadPoolExecutor.java:180) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:204) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) at java.lang.Thread.run(Thread.java:662)Caused by: java.net.SocketException: Broken pipe at java.net.SocketOutputStream.socketWrite0(Native Method) at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92) at java.net.SocketOutputStream.write(SocketOutputStream.java:136) at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:65) at java.io.BufferedOutputStream.write(BufferedOutputStream.java:109) at java.io.ObjectOutputStream$BlockDataOutputStream.drain(ObjectOutputStream.java:1847) at java.io.ObjectOutputStream$BlockDataOutputStream.writeByte(ObjectOutputStream.java:1885) at java.io.ObjectOutputStream.writeFatalException(ObjectOutputStream.java:1546) at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:333) at sun.rmi.server.UnicastRef.marshalValue(UnicastRef.java:274) at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:133) ... 22 more补充:相同的程序,放在linux版本相同,JDK版本相同的服务器C去调用A不会出现以上问题,B、和C的防火墙策略是相同的,防火墙关了也会有这个问题,就算把服务端部署在B,B内部调用也会间歇性出现该问题。奔溃了,搞不定啊,求解。。。。 问题补充:aronlulu 写道
解决方案
最后一个办法,tcpdump抓包。tcpdump -Xs 0 -i 网卡名如eth0 -vv -w a.cap port 端口号
解决方案二:
用Wireshark分析a.cap文件,看tcp层的码流交互情况。
解决方案三:
/etc/sysctl.conf这个文件只需要看下A跟B的一不一样就可以了。不一样就换成A的。线程问题需要关注,你如何知道你每次就一个线程在调用。每次开一个线程,那上个线程已经确保执行结束了?还是说没结束就强制掐掉。既然每次就一个线程调用,为什么还要用线程池呢。单线程引入线程池只会增加问题,不会减少问题定位复杂度。
解决方案四:
at com.dataservice.EventSenderImpl.sendEventTask(EventSenderImpl.java:191) at com.dataservice.EventSenderImpl.access$0(EventSenderImpl.java:173) at com.dataservice.EventSenderImpl$ResSendTask.run(EventSenderImpl.java:166) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441) at java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:317) at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:150) 显然有多线程。要么你就检查你的网络,包括tcp层的配置,/etc/sysctl.conf文件在硬件没坏的情况下,程序也一模一样的情况下,就剩配置了。
解决方案五:
B的调用方式是不是与C一模一样。间歇性的出现意思是不是说时好时坏,不是每次调用都会出现。这个应该是多线程调用同一端口造成的。试试写个简单的单线程定时重复调用程序挂在B上跑,看会不会出现调用失败。