Skip to content

Commit 279e51d

Browse files
committed
fix: hanging process when TLS alert happens during mqtt_connect (tls_alert)
Similar to #279 This time, the error is a bit different, but the effect is the same: ``` 18:17:09.437 [info] [reason: {:tls_alert, {:certificate_revoked, ~c"TLS client: In state connection received SERVER ALERT: Fatal - Certificate Revoked\n"}}, msg: ~c"failed_to_send_connect_packet", clientid: "emqtt-erlang-9e2056f5415da439bfce"] ``` ``` Testing apps.emqx.emqx_crl_cache_SUITE: *** FAILED test case 1 *** %%% emqx_crl_cache_SUITE ==> t_revoked: FAILED %%% emqx_crl_cache_SUITE ==> {{case_clause,{error,connack_timeout}}, [{emqx_crl_cache_SUITE,t_revoked,1, [{file,"test/emqx_crl_cache_SUITE.erl"},{line,969}]}, {test_server,ts_tc,3,[{file,"test_server.erl"},{line,1794}]}, {test_server,run_test_case_eval1,6,[{file,"test_server.erl"},{line,1303}]}, {test_server,run_test_case_eval,9,[{file,"test_server.erl"},{line,1235}]}]} ``` Simple to reproduce with a small sleep before `mqtt_connect`: ```diff modified src/emqtt.erl @@ -1032,6 +1032,7 @@ do_connect(ConnMod, #state{pending_calls = Pendings, socket = NewSock, pending_calls = NewPendings }), + timer:sleep(50), case mqtt_connect(State3) of {ok, State4} -> {ok, State4}; ```
1 parent 8340d9f commit 279e51d

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/emqtt.erl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,6 +1034,11 @@ do_connect(ConnMod, #state{pending_calls = Pendings,
10341034
%% connect on a TLS socket, for example, if the client's TLS
10351035
%% certificate is revoked and the server closes the connection.
10361036
{error, closed};
1037+
{error, {tls_alert, _} = Reason} ->
1038+
%% If we receive a TLS alert here such as `Certificate Revoked`, there
1039+
%% is no other socket event to be received, and thus we must terminate
1040+
%% now to avoid hanging and then getting a `{error, connack_timeout}`.
1041+
{error, Reason};
10371042
{error, Reason} ->
10381043
?LOG(info, "failed_to_send_connect_packet", #{reason => Reason}, State),
10391044
%% Failed to send CONNECT packet.

0 commit comments

Comments
 (0)