Skip to content

Commit d5379c3

Browse files
committed
There is no socket read timeout set currently and default is to set to zero i.e. wait forever. Adding socket read timeout will help recovering from edge cases where packets are lost on the wire and MqttInputStream.readMqttWireMessage() fails to notify ClientState. In fact, readMqttWireMessage does handle the case for exception thrown due to socket read timeout and ignore it.
Signed-off-by: Rehan Shaukat <rehan.shaukat@gmail.com>
1 parent dfca976 commit d5379c3

2 files changed

Lines changed: 3 additions & 1 deletion

File tree

  • org.eclipse.paho.client.mqttv3/src/main/java/org/eclipse/paho/client/mqttv3/internal
  • org.eclipse.paho.mqttv5.client/src/main/java/org/eclipse/paho/mqttv5/client/internal

org.eclipse.paho.client.mqttv3/src/main/java/org/eclipse/paho/client/mqttv3/internal/TCPNetworkModule.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ public void start() throws IOException, MqttException {
8080
socket = factory.createSocket();
8181
socket.connect(sockaddr, conTimeout*1000);
8282
}
83+
socket.setSoTimeout(1000);
8384
}
8485
catch (ConnectException ex) {
8586
//@TRACE 250=Failed to create TCP socket

org.eclipse.paho.mqttv5.client/src/main/java/org/eclipse/paho/mqttv5/client/internal/TCPNetworkModule.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ public void start() throws IOException, MqttException {
8383
socket = factory.createSocket();
8484
socket.connect(sockaddr, conTimeout*1000);
8585
}
86-
86+
socket.setSoTimeout(1000);
87+
8788
// SetTcpNoDelay was originally set ot true disabling Nagle's algorithm.
8889
// This should not be required.
8990
// socket.setTcpNoDelay(true); // TCP_NODELAY on, which means we do not use Nagle's algorithm

0 commit comments

Comments
 (0)