vertx-mqtt icon indicating copy to clipboard operation
vertx-mqtt copied to clipboard

Mqtt Client doesn't close connection when there is no reply to CONNECT

Open ctron opened this issue 7 years ago • 11 comments

Assuming the following happens:

  • TCP connect is OK
  • Client sends CONNECT
  • Waits for CONACK

If the CONACK never is received by the client, but still the TCP connection remains open, then MQTT Client never reports back.

ctron avatar Dec 07 '17 14:12 ctron

would a TCP idle timeout work in this case ?

vietj avatar Dec 07 '17 15:12 vietj

No. As by default a TCP keepalive timeout still is somewhat around two days IIRC.

ctron avatar Dec 08 '17 09:12 ctron

@ctron, do you think we should have something like "timeout of CONNACK" right?

Sammers21 avatar Dec 08 '17 12:12 Sammers21

I guess so. Maybe there already is a communication idle timeout on which the client disconnects which could be re-used.

ctron avatar Dec 08 '17 13:12 ctron

I think that's a more general question about dead connection detection : does MQTT have PING message ?

vietj avatar Dec 08 '17 14:12 vietj

@ctron there is not such timeout because it's protocol dependant (like PING frames for websocket, HTTP/2, etc...)

vietj avatar Dec 08 '17 14:12 vietj

@ctron as @vietj said maybe it's something related to the PINGREQ/PINGRESP at MQTT level. If the CONNACK packet is "lost", the MQTT server should then closes the connection if it doesn't receive the PINGREQ in the timeout specified in the CONNECT packet. What's the broker you are using with the MQTT client. It's also true that the keepalive mechanism can be disabled (if timeout is set to 0 in the CONNECT packet) so closing connection from server side can't happen.

ppatierno avatar Dec 08 '17 14:12 ppatierno

@ctron but it's also true that MQTT 3.1.1 says the following :

If the Client does not receive a CONNACK Packet from the Server within a reasonable amount of time, the Client SHOULD close the Network Connection. A "reasonable" amount of time depends on the type of application and the communications infrastructure.

so it's something that we don't have in the current MQTT client :-(

ppatierno avatar Dec 08 '17 14:12 ppatierno

we should use PINGREQ/PINGRESP with a timeout to create an hearbeat to handle this case

vietj avatar Dec 08 '17 14:12 vietj

@vietj I don't think that using the PING mechanism is the right solution just because as I said it can be disabled (keep alive = 0 in the CONNECT packet) so it means that client and server DON'T HAVE TO exchanged PINGREQ/PINGRESP.

ppatierno avatar Dec 08 '17 14:12 ppatierno

The client should simply have an option to configure the maximum amount of time it will wait for a CONNACK from the server before it closes the connection. BTW the client has the same problem when sending a PUBLISH for a message using QoS 1 and/or 2. It will not time out while waiting for a PUBACK. Thus, if the server does not send a PUBACK (or it gets lost somehow), the message will remain in the client's outbound queue forever, eventually preventing the client to send additional messages because the max messages in flight limit is exceeded. FMPOV the same time out could be used for both the CONNACK as well as the PUBACK as it should in both cases be (mostly) dependent on the characteristics of the underlying networking infrastructure.

@ctron @ppatierno @vietj WDYT?

sophokles73 avatar Aug 10 '20 09:08 sophokles73