Search code examples
javadockersocketstcpdocker-compose

TCP Java Socket custom timeouts not working only on docker


This code works perfectly on my machine default O.S but not in Docker, and I didn't found any documentation about it.

    clientSocket = new Socket();

    SocketAddress sockaddr = new InetSocketAddress(propertyFile.getProperty("tcp.pod.ip"),
            Integer.parseInt(propertyFile.getProperty("tcp.pod.port")));

    clientSocket.connect(sockaddr, 150);

    clientSocket.setTcpNoDelay(true);

The part that does not work in docker is the clientSocket connect timeout(second parameter), it takes the default timeout instead the one I am passing to him. Everything else works perfectly.


Solution

  • We have been testing for months but the telemetry was just from our O.S through two access points to the prototypes, so if an ack is not received because the protopype died I will see it(We were using this to see if there were communication)

    With docker there is a proxy between the O.S and the docker engine so you will see always there is connection because the acks arrives always from the container to the O.S socket.

    The solution to implement a keep alive in the application layer(you can not do this in the protocol layer).

    This post explain it better: Finding out if a message over tcp was delivered