FactbirdHQ / mqttrust

MQTT client for embedded devices, written in rust
50 stars 5 forks source link

MQTT does not close socket in the event of connection failure #46

Closed unizippro closed 2 years ago

unizippro commented 2 years ago

If an error arises while connecting the socket to the remote IP, the socket is not closed before being dropped.

Example:

161502 DEBUG [TCP] Connect socket
161521 DEBUG Sending command with too long payload (81 bytes) to log! #(Connect msg)
161541 ERROR Received error response InvalidResponse
161541 ERROR InvalidResponse: b"\xaa\x00M\x00DAT+UDCP=\"tcp://54.171.23.225:8883/?ca=root_ca&cert=cert&privKey=priv_key\"\r\nU"
161561 DEBUG Sending command with too long payload (67 bytes) to log!  #(DNS)
161581 DEBUG Received response: "b"\xaa\x00\x08\x00E\r\nOK\r\nU""
161641 DEBUG Received response: "b"\xaa\x00X\x00A+UUPING:1,32,\"a3f8k0ccx04zas-ats.iot.eu-west-1.amazonaws.com\",\"54.171.23.225\",231,45\r\nU""
161642 TRACE [URC] PingResponse
161642 DEBUG [TCP] Opening socket
161643 DEBUG Adding socket! 0 Tcp
161643 DEBUG [Socket Set] Adding to: [(Handle(0), Tcp(State::Created)), (Handle(2), Tcp(State::Connected)), (Handle(4), Tcp(State::Connected))]
161644 ERROR [TCP] Opening socket Error: DuplicateSocket

This call is at eventloop.rs:341, where the socket is dropped without calling close first.

Solution

Add a close call to the call in eventloop.rs:341