小编典典

spring客户端套接字连接重置

tomcat

我双方都使用spring3.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 Client上 重置Connection

客户端配置

<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下的readTimeout值设置为30分钟,但在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 下看不到与连接超时有关的设置。

请建议该怎么办?


阅读 451

收藏
2020-06-16

共1个答案

小编典典

经过一些调试后,我发现我的 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

希望这也能帮助其他人

2020-06-16