AIX:IBM Java:java.net.SocketException:连接超时:可能是由于地址无效

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/213857/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 11:28:31  来源:igfitidea点击:

AIX: IBM Java: java.net.SocketException: Connection timed out:could be due to invalid address

javasslaixapache-commons-httpclient

提问by jsight

We have seen the following exceptions very frequently on IBM AIX when attempting to make an SSL connection to our server:

尝试与我们的服务器建立 SSL 连接时,我们在 IBM AIX 上经常看到以下异常:

java.net.SocketException: Socket closed
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.a(DashoA6275(Compiled Code))
at com.sun.net.ssl.internal.ssl.AppOutputStream.write(DashoA6275(Compiled Code))
at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java(Inlined Compiled Code))
at java.io.BufferedOutputStream.flush(BufferedOutputStream.java(Compiled Code))
at java.io.FilterOutputStream.flush(FilterOutputStream.java(Compiled Code))
at org.apache.commons.httpclient.methods.EntityEnclosingMethod.writeRequestBody(EntityEnclosingMethod.java(Compiled Code))
at org.apache.commons.httpclient.HttpMethodBase.writeRequest(HttpMethodBase.java(Compiled Code))
at org.apache.commons.httpclient.HttpMethodBase.execute(HttpMethodBase.java(Compiled Code))
at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java(Compiled Code))
at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java(Compiled Code))
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java(Compiled Code))
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java(Inlined Compiled Code))
at com.eximtechnologies.httptransport.client.ClientTransport.receiveMessages(ClientTransport.java(Compiled Code))
at com.eximtechnologies.httptransport.client.ClientTransport.receiveMessages(ClientTransport.java(Inlined Compiled Code))
at com.eximtechnologies.ecserver.connection.XMSHTTPConnection.checkForNewMessages(XMSHTTPConnection.java(Compiled Code))
at com.eximtechnologies.ecserver.connection.XMSHTTPConnection.timeoutExpired(XMSHTTPConnection.java(Compiled Code))
at com.eximtechnologies.xmd.timer.TimerEvent.run(TimerEvent.java(Compiled Code))

From the error, you would think this was just a network problem, but the client had never experienced the problem before about 2 months ago, and AFAIK, there haven't been any changes to the network layout.

从错误来看,你会认为这只是一个网络问题,但客户端在大约 2 个月前之前从未遇到过这个问题,而且 AFAIK,网络布局没有任何变化。

We also receive this fairly frequently:

我们也经常收到这个:

java.net.SocketException: Connection timed out:could be due to invalid address
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:336)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:201)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:188)
at java.net.Socket.connect(Socket.java:478)
at java.net.Socket.connect(Socket.java:428)
at java.net.Socket.<init>(Socket.java:335)
at java.net.Socket.<init>(Socket.java:210)
at javax.net.ssl.SSLSocket.<init>(Unknown Source)

I'm suspecting that this is an AIX problem, but I guess it could be a firewall issue? I also saw some people in google searches hinting at a problem with commons http, but I couldn't see how that would be related.

我怀疑这是 AIX 问题,但我想这可能是防火墙问题?我还在谷歌搜索中看到一些人暗示 commons http 有问题,但我看不出这有什么关系。

Is this something that others have seen with AIX recently?

这是其他人最近在 AIX 上看到的吗?

回答by Steve B.

I have had issues with http client that were corrected by using a multithreaded connection. We fixed it by moving from the first to the second of the configurations below:

我有使用多线程连接纠正的 http 客户端问题。我们通过从下面的第一个配置移动到第二个配置来修复它:

<bean id="httpClient" class="org.springframework.remoting.httpinvoker.CommonsHttpInvokerRequestExecutor">
    <property name="httpClient">
        <bean class="org.apache.commons.httpclient.HttpClient">
            <property name="connectionTimeout"><value>1000</value></property>
            <property name="timeout"><value>3000</value></property>
        </bean>
    </property>
</bean>

<bean id="httpClient" class="org.springframework.remoting.httpinvoker.CommonsHttpInvokerRequestExecutor">
    <property name="httpClient">
        <bean class="org.apache.commons.httpclient.HttpClient">
            <property name="connectionTimeout"><value>1000</value></property>
            <property name="timeout"><value>3000</value></property>
            <property name="httpConnectionManager">
              <bean class="org.apache.commons.httpclient.MultiThreadedHttpConnectionManager" destroy-method="shutdown">
                <property name="params">
                  <bean class="org.apache.commons.httpclient.params.HttpConnectionManagerParams">
                    <property name="defaultMaxConnectionsPerHost" value="20" />
                  </bean>
                </property>
              </bean>
            </property>
        </bean>
    </property>
</bean>

回答by Alexander

"java.net.SocketException: Socket closed" means that your side closed the socket. You say that this happens when you attempt to make an SSL connection to your server. However, the stack trace suggests that this happens when HTTPClient attempts to write an HTTP request over an already established connection.

“java.net.SocketException: Socket closed”表示你方关闭了socket。您说当您尝试与服务器建立 SSL 连接时会发生这种情况。但是,堆栈跟踪表明,当 HTTPClient 尝试通过已建立的连接写入 HTTP 请求时,会发生这种情况。

This could happen if, for example, you somehow managed to make HTTPClient send a request via a connection that was previously closed by HTTPClient, or, more likely, by some other code on your side. Check whether you are accessing the underlying socket somewhere. Or it could be that the socket is closed by the SSL/TLS protocol (if I'm not mistaken, SSL/TLS has its own higher-level protocol for closing the underlying connection), but HTTPClient somehow managed to not notice this (don't know whether it's possible, but, say, the remote side closed the SSL connection but was using HTTP/1.1 persistent connections and didn't set a Connection: close response).

例如,如果您以某种方式设法使 HTTPClient 通过先前由 HTTPClient 关闭的连接发送请求,或者更有可能是由您身边的其他代码关闭,则可能会发生这种情况。检查您是否正在某处访问底层套接字。或者可能是 SSL/TLS 协议关闭了套接字(如果我没记错的话,SSL/TLS 有自己的更高级别的协议来关闭底层连接),但是 HTTPClient 以某种方式设法没有注意到这一点(不要不知道是否可能,但是,比如说,远程端关闭了 SSL 连接,但使用的是 HTTP/1.1 持久连接并且没有设置连接:关闭响应)。

You can troubleshoot these issues by analyzing the TCP traffic using tcpdump/Wireshark. You could also start an stunnel on a machine to the server's HTTPS port, then make your code communicate with the server over plain HTTP via this tunnel. This should enable you to see the HTTP traffic in plaintext.

您可以通过使用 tcpdump/Wireshark 分析 TCP 流量来解决这些问题。您还可以在一台机器上启动一个到服务器 HTTPS 端口的 stunnel,然后让您的代码通过此隧道通过普通 HTTP 与服务器通信。这应该使您能够以纯文本形式查看 HTTP 流量。

"java.net.SocketException: Connection timed out" means that the TCP connection could not be established due to a timeout. Could be that the packets are dropped by a firewall. For example, it could be that you need to use an HTTP proxy to make HTTPS requests. It could also be that the server machine is really busy or the network is really busy. Again, I suggest you try tcpdump/Wireshark to see what's going on at the TCP level.

“java.net.SocketException: Connection timed out”表示由于超时无法建立 TCP 连接。可能是数据包被防火墙丢弃了。例如,您可能需要使用 HTTP 代理来发出 HTTPS 请求。也可能是服务器机器真的很忙或者网络真的很忙。同样,我建议您尝试 tcpdump/Wireshark 以查看 TCP 级别发生了什么。

回答by shivarajan

I won't be surprised if it doesn't work!

如果它不起作用,我不会感到惊讶!

the specified timeout is the timeout for getting connection from the specified connection manager and not actual socket or server timeout which needs different set of settings.

指定的超时是从指定的连接管理器获取连接的超时,而不是需要不同设置的实际套接字或服务器超时。