Browse Source
Merge pull request #13754 from artem-barysh-dev/fix-mqtt-disconect
Fixed MQTT client disconnect
pull/13763/head
Viacheslav Klimov
1 year ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with
1 additions and
2 deletions
-
netty-mqtt/src/main/java/org/thingsboard/mqtt/MqttClientImpl.java
|
|
|
@ -462,19 +462,18 @@ final class MqttClientImpl implements MqttClient { |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
disconnected = true; |
|
|
|
log.trace("[{}] Disconnecting from server", channel != null ? channel.id() : "UNKNOWN"); |
|
|
|
if (this.channel != null) { |
|
|
|
MqttMessage message = new MqttMessage(new MqttFixedHeader(MqttMessageType.DISCONNECT, false, MqttQoS.AT_MOST_ONCE, false, 0)); |
|
|
|
|
|
|
|
sendAndFlushPacket(message).addListener((ChannelFutureListener) future -> { |
|
|
|
future.channel().close(); |
|
|
|
disconnected = true; |
|
|
|
}); |
|
|
|
eventLoop.schedule(() -> { |
|
|
|
if (channel.isOpen()) { |
|
|
|
log.trace("[{}] Channel still open after {} second; forcing close now", channel.id(), DISCONNECT_FALLBACK_DELAY_SECS); |
|
|
|
this.channel.close(); |
|
|
|
disconnected = true; |
|
|
|
} |
|
|
|
}, DISCONNECT_FALLBACK_DELAY_SECS, TimeUnit.SECONDS); |
|
|
|
} |
|
|
|
|