eclipse-paho / eclipse-paho/paho.mqtt.java

SSLSocket is not closed when disconnected from the broker

Open
#467 2 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Java
Stars
2.3k
Forks
919
PR merge metrics
No merged PRs in 30d

Description

Hi,
Our project uses the paho in the unstable network conditions. We sometimes get the broker unreachable for a few minutes.
If the broker is unreachable for a long time, the connection to the broker is closed when the keepAliveInterval timeout expires, but the underlying socket is not closed if it is SSLSocket.

In `TCPNetworkModule#stop`, `shutdownInput` is called before `close`. However, if the socket is a SSLSocket, `close` is never called since `shutdownInput` always throws `UnsupportedOperationException`.
```
public void stop() throws IOException {
if (socket != null) {
// CDA: an attempt is made to stop the receiver cleanly before closing the socket.
...
// want to move it in SSLNetworkModule.

socket.shutdownInput();
socket.close();
}
```

The netstat log shows that the old tcp connection is still alive even after the reconnect cycle has begun.
```
pi@8e65eabebd90:~/work$ netstat -ant
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp6 0 11479 172.17.0.2:46858 184.172.124.189:8883 ESTABLISHED
tcp6 0 1 172.17.0.2:46860 184.172.124.189:8883 SYN_SENT
```

- [x] Bug exists Release Version 1.2.0 ( Master Branch)
- [x] Bug exists in Snapshot Version 1.2.1-SNAPSHOT (Develop Branch)
- [?] Bug exists in MQTTv5 Version (mqttv5-new Branch)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.