spring hessian客户端套接字连接重置

时间:2013-03-01 09:38:28

标签: tomcat spring-security rmi hessian spring-remoting

我正在使用spring 3.1.0,com.springsource.com.caucho-3.2.1.jar和tomcat-6.0.33双方(客户端/服务器)。除了长时间服务(超过9/10分钟)之外,所有远程服务呼叫都正常运行,没有任何问题。

我正在使用Spring-Security保护远程呼叫。

我创建了一个新的远程服务,大约需要30分钟才能在真正的方案中对客户做出响应。如果执行时间少于9.xx / 10分钟,但在达到9.xx / 10分钟后,我的Hessian客户端上的连接重置,该服务可以正常运行。

客户端配置

<bean id="someService" class="org.springframework.remoting.caucho.HessianProxyFactoryBean">
    <property name="serviceUrl" value="http://hostname:8080/remoting/someService"/>
    <property name="serviceInterface" value="com.SomeService"/>
    <property name="username" value="${service.username}"/>
    <property name="password" value="${service.password}"/>
</bean>

服务器配置

<bean id="someService" class="com.SomeService" />

<bean name="/someService" class="org.springframework.remoting.caucho.HessianServiceExporter">
    <property name="service" ref="someService" />
    <property name="serviceInterface" value="com.SomeService" />
</bean>

客户端 - 堆栈跟踪:

2013-Feb-28 17:48:19 DEBUG [http-8080-1] com.SomeService:85 - Calling Some Service
2013-Feb-28 17:58:16 ERROR [http-8080-1] com.SomeService:113 - 
org.springframework.remoting.RemoteConnectFailureException: 
Cannot connect to Hessian remote service at [http://hostname:8080/remoting/someService]; 
nested exception is com.caucho.hessian.client.HessianConnectionException: 
500: java.net.SocketException: Connection reset
at org.springframework.remoting.caucho.HessianClientInterceptor.convertHessianAccessException(HessianClientInterceptor.java:262)

服务器端 - Tomcat(localhost.log)

SEVERE: Servlet.service() for servlet [remoting] in context with path [/JTService] 
threw exception [Hessian skeleton invocation failed; nested exception is
ClientAbortException:  java.net.SocketException: Connection reset] with root cause
java.net.SocketException: Connection reset
    at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:96)

我尝试在HessianProxyFactoryBean下设置30分钟的readTimeout值,但在9.xx / 10分钟后获得相同的异常。然而,当我尝试使用readTimeout 2分钟时,我会在2分钟后读取超时

将readTimeout设置为2分钟后,我得到了:

2013-Feb-28 17:44:10 ERROR [http-8080-1] com.SomeService:113 - org.springframework.remoting.RemoteConnectFailureException: 
Cannot connect to Hessian remote service at [http://hostname:8080/remoting/someService]; 
nested exception is com.caucho.hessian.client.HessianConnectionException: 500: java.net.SocketTimeoutException: Read timed out
org.springframework.remoting.RemoteConnectFailureException: 
Cannot connect to Hessian remote service at [http://hostname:8080/remoting/someService]; 
nested exception is com.caucho.hessian.client.HessianConnectionException: 500: java.net.SocketTimeoutException: Read timed out

和readTimeout一样,我没有看到和设置与 HessianProxyFactoryBean 下的连接超时有关。

请建议做什么?

1 个答案:

答案 0 :(得分:0)

经过一些调试后,我发现我的 Linux / CentOS服务器在几分钟后关闭了网络连接。在* / proc / sys / net / ipv4 / tcp_keepalive_time *下增加连接保持活动时间后解决了连接超时问题。

Linux控制台示例输出:

以秒为单位显示保持活动时间

[root@hostname ~]# cat /proc/sys/net/ipv4/tcp_keepalive_time 
7200

使用以下命令增加值

[root@hostname ~]# echo "21600" > /proc/sys/net/ipv4/tcp_keepalive_time

希望这也有助于其他人