JAX-WS client closes tcp connection with FIN,ACK

3.4k Views Asked by At

We have implemented a JAX-WS client and facing the following issue. It is a stateful session sync flow. The client makes two requests/response initially one by one sucessfully

3 different Cases for the issue

1) After the first two request/response, I am making a third request which is after 6th and 9th( two different test cases) seconds after the receiving the response of 2nd request. In both the cases, from the tcpdump I could see that our client is closing the existing tcp connection by [FIN,ACK] and opening a new connection for the 3rd request. But since this is stateful session, the server expects the connection should not be cloased and so we are getting error response.

2) If I make the 3rd request within 5 seconds after 2nd request, then the same tcp connection is re-used.

3) If I dont make 3rd request at all, then automatcially after 10 seconds(by [FIN,ACK] from the 2nd request, the tcp conenction is closed by the client.

Basically the problem is client application is closing the tcp connection by itself. I have tried by setting all the following properties. But still I am facing the same problem.

   BindingProvider bp = (BindingProvider)port;
   Map<String, Object> context = bp.getRequestContext();
  context.put(BindingProvider.SESSION_MAINTAIN_PROPERTY, true);

  context.put(JAXWSProperties.CONNECT_TIMEOUT, 60000);
  context.put(JAXWSProperties.REQUEST_TIMEOUT, 70000);

  context.put("com.sun.xml.ws.connect.timeout", 50000);
  context.put("com.sun.xml.ws.request.timeout", 50000);

  context.put("javax.xml.ws.client.connectionTimeout", 60000);
  context.put("javax.xml.ws.client.receiveTimeout", 70000);

I am attching the screenshot of pcap file for your reference. Here you can see [FIN,ACK] issued by client after 6 seconds. enter image description here

I am not sure if there is any other config which I am missing. Can you please help me to resolve this issue ?

Vesrions: Java : jdk1.6.0_21

Metro : Metro/2.3

HTTP: 1.1

One more thing I have noticed is, there is a "Connection: keep-alive" in request but its not there in server's response. Not sure if this could be a problem

1

There are 1 best solutions below

0
On

I went into further investigation since I was having the same problem. What I found is that this is HTTP 1.1 default behavior. from wikipedia(persistent connection):

In HTTP 1.1, all connections are considered persistent unless declared otherwise.1 The HTTP persistent connections do not use separate keepalive messages, they just allow multiple requests to use a single connection. However, the default connection timeout of Apache httpd 1.3 and 2.0 is as little as 15 seconds2[3] and just 5 seconds for Apache httpd 2.2 and above.[4][5] The advantage of a short timeout is the ability to deliver multiple components of a web page quickly while not consuming resources to run multiple server processes or threads for too long

So basically what is happening is that your client is closing the connection after it's idle for the configured amount of time(connection-timeout). Jax-ws implements by default apache HttpUrlConnection which has a preconfigured 15 seconds timeout. In our client running on Weblogic 12.1.3 the following configuration worked for us:

final BindingProvider binding = (BindingProvider) port;
final Map<String, Object> ctx = binding.getRequestContext();
ctx.put("com.sun.xml.ws.request.timeout", requestTimeOut);
ctx.put("com.sun.xml.ws.connect.timeout", connectTimeOut);