gausby / tortoise

A MQTT Client written in Elixir
Apache License 2.0
314 stars 54 forks source link

Catch other connection errors #93

Closed fhunleth closed 6 years ago

fhunleth commented 6 years ago

I was receiving TLS certificate unknown alerts from the server. They were handled differently from other connection errors. I wasn't completely sure if you wanted to handle errors on a case-by-case basis to see if they could benefit from more information or not. The only other error that I've seen so far is {:error, {:tls_alert, something}} if that's the case.

coveralls commented 6 years ago

Pull Request Test Coverage Report for Build 1


Totals Coverage Status
Change from base Build 35: 0.0%
Covered Lines: 564
Relevant Lines: 642

đź’› - Coveralls
gausby commented 6 years ago

I have rewritten much of the connection logic in the MQTT 5 branch…this should allow us to write transport specific error message and handling…so I think we should wait and decide till I get the MQTT 5 branch in a state where it can take over, and I can backport it so it works with MQTT 3.1.1 as well (so we only have one interface).

I could merge it in, but soon it will be a slightly different world (sorry, some parts of your callback modules needs to be changed a bit :))…is it really, really important?, because as such I think I will let it wait for the MQTT 5 branch to be completed (though I don't think the rebase would be that hard to solve)

fhunleth commented 6 years ago

Sounds good. Now that I've fixed the certificate issue, this isn't a big deal.

rbino commented 6 years ago

Hi everybody! I just want to add here that another error that isn't handled (and would be handled by this PR) is :timeout

11:32:31.643 [error] GenServer {Tortoise.Registry, {Tortoise.Connection, "test"}} terminating
** (WithClauseError) no with clause matching: {:error, :timeout}
    (tortoise) lib/tortoise/connection.ex:583: Tortoise.Connection.do_connect/2
    (tortoise) lib/tortoise/connection.ex:385: Tortoise.Connection.handle_info/2
    (stdlib) gen_server.erl:616: :gen_server.try_dispatch/4
    (stdlib) gen_server.erl:686: :gen_server.handle_msg/6
    (stdlib) proc_lib.erl:247: :proc_lib.init_p_do_apply/3

Sadly this causes a nasty avalanche effect since when a :timeout occurs, the Connection doesn't back off but just crashes and tries to reconnect immediately.

gausby commented 6 years ago

@rbino oh, good catch; I will merge it then!

gausby commented 6 years ago

Released in v0.9.3

gausby commented 6 years ago

The MQTT 5 stuff is slowly progressing, by the way. Hopefully I will work on it this weekend—the user-defined properties keep causing design issues, so they really are a blessing and a curse :)

rbino commented 6 years ago

I've opened https://github.com/gausby/tortoise/pull/94 since merging this doesn't fix completely the timeout problem (since it is not classified as connectivity error)