linux网络设置POST 2小时后失败

时间:2012-06-24 17:04:32

标签: java httpurlconnection recv

我有以下测试代码正常运行很长的POST请求(超过2小时):

        URL postURL = new URL(url);            
        con = (HttpURLConnection) postURL.openConnection();            
        con.setUseCaches(false);
        con.setDoOutput(true);
        con.setDoInput(true);
        con.setRequestMethod("POST");            
        OutputStream out = con.getOutputStream();
        OutputStreamWriter wout = new OutputStreamWriter(out, "UTF-8");
        wout.write(xmlRequest);
        wout.flush();
        out.close();
        con.connect();            
        int httpResponseCode = HttpURLConnection.HTTP_SERVER_ERROR;
        try {
            httpResponseCode = con.getResponseCode();
        } catch (IOException e) {
            log(e.toString() + " Error retrieving the status code");
        }
        log("Failure status code " + httpResponseCode + " received: ");

我从一个主机到另一个主机运行这个帖子,它在所有环境中运行正常,除了一个确切的linux redhat主机 - 当我从这个主机运行这个代码时我得到了异常:

java.net.SocketException:recv()失败,错误= 104连接重置对象错误检索状态码
收到失败状态代码500.

目标服务器主机在所有测试中都是同一主机。所以区别仅在于客户端来电主机。

所以我试图了解这台linux机器上的确切tcp设置是在两小时后导致接收失败。

我同意在这里因为发送帖子的“错误”使用并等待超过2小时的回复而受到任何指责;)但问题是导致这种情况的原因

2 个答案:

答案 0 :(得分:0)

谷歌7200秒tcp redhat等等

   tcp_keepalive_time (integer; default: 7200; since Linux 2.2)
          The number of seconds a connection needs to be idle  before  TCP
          begins sending out keep-alive probes.  Keep-alives are only sent
          when the SO_KEEPALIVE socket option  is  enabled.   The  default
          value  is  7200 seconds (2 hours).  An idle connection is termi-
          nated after approximately an additional 11 minutes (9 probes  an
          interval of 75 seconds apart) when keep-alive is enabled.

          Note that underlying connection tracking mechanisms and applica-
          tion timeouts may be much shorter.

答案 1 :(得分:0)

不同之处在于,一个客户端主机位于不同的网段,路由器在超时后终止了空闲会话。