I’ve PUSH client (which connect() to the server)and, a PULL server (which bind() on a port 8082)
Now PUSH client faces some network issue (FYI: I've turned of wifi to prduce the scenario of a production env.)
Due to this, messages gets stuck into client’s send queue, due to this the OS closes that tcp connection
I'm not sure but,I think OS closes the socket connection due to high ammount of messages are pending in send queue, I've verified this by limiting number of messages and in result i've observed that the ammount of time when socket is terminated is increased.
I've let the socket ESTABLISH connection to the server then,
Case 1 : I'm sending a message with some 240 bytes, every 10 MS, after turning off wifi, the socket connection is teminated after roughly 2 mins. ->Linux: 2mins, Windows:1mins
Case 2: I'm sending a message with some 240bytes, every 60Seconds, after turning off wifi, the socket connection is teminated after roughly 7-8 mins. ->Linux: 7mins, Windows:5mins
Case 3: I'm seding no messages at all, after turning off wifi, the socket connection is teminated never. (Observed for atleat one hour)
Now again when the connection comes back to normal (turned on the wifi) the ZMQ it self tries to reconnect to the server hence it creates a new TCP connection with new port of client.
Here concern is client side only one connection is open but at my server side the old connection is still in ESTABLISH state as client not provided the close call on that socket
And this create a very large ammount of open connections in my application. (Connection leak)
Now, I've observed that if i'm not letting socket establish connection to the server (i.e socket is in SYN-SENT) and set the send high watermark to 10. In this case after sending 20 or 30 messages, call to the send() method is blocked.
So my question is the same thing does not happen after a socket goes into ESTABLISHED state.
Please correct if i'm thinking in wrong direction to solve the above problem. There may be a different approach or flag to solve the above problem. But my ultimate goal is to solve that problem
Also gone through some questions.ZeroMQ Client Lose Connection
- I've tried setting TCP Keep Alive to 1
- I've set all above options before call to the bind() or connect()
- I've tried setting the TCP_KEEPALIVE_IDLE to 300 and TCP_KEEPALIVE_INTVL 300 (but nothing works)
Server.java
public class Server { public static void start() { var server = Bootstrap.zcontext().socket(SocketType.PULL); server.setTCPKeepAlive(1); server.setHWM(10); server.setRcvHWM(10); server.bind("tcp://127.0.0.1:8082"); new Thread(() -> { while (true) { var bytes = server.recv(); System.out.println("received bytes " + Buffer.buffer(bytes)); } }).start(); }}
Client.java
public class Client { public static void start() { var client = Bootstrap.zcontext().socket(SocketType.PUSH); client.setSendTimeOut(0); client.setLinger(0); client.setTCPKeepAlive(1); client.setHWM(10); client.setSndHWM(10); client.connect("tcp://127.0.0.1:8082"); LockSupport.parkNanos(Duration.ofMillis(100).toNanos()); new Thread(() -> { while (true) { System.out.println("Before send"); client.send("Hello World".getBytes(StandardCharsets.UTF_8)); System.out.println("After send"); try { Thread.sleep(Duration.ofMillis(10).toMillis()); } catch (InterruptedException e) { throw new RuntimeException(e); } } }).start(); }}