-
Notifications
You must be signed in to change notification settings - Fork 175
port fixes to main-1.13 #296
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fd757b4
to
1af3cbf
Compare
`emqx_sock` defined an internal record for storing both the tcp and ssl socket ports. However, when we have a TLS error such as `bad_certificate`, `ssl` sends a message containing the inner SSL socket, not this internal emqtt record, and there were missing clauses to handle that. This caused `emqtt` to: i) Hang indefinitely if `connect_timeout` is not specified; ii) Fail with `{error, connack_timeout}` if `connect_timeout` is a finite value.
Example error: https://github.com/emqx/emqx/actions/runs/13924497502?pr=14893 ``` *** System report during emqx_crl_cache_SUITE:t_revoked/1 2025-03-18 14:10:14.557 *** 🔗 =NOTICE REPORT==== 18-Mar-2025::14:10:14.557158 === TLS server: In state wait_cert at ssl_handshake.erl:2156 generated SERVER ALERT: Fatal - Certificate Revoked *** System report during emqx_crl_cache_SUITE:t_revoked/1 2025-03-18 14:10:14.558 *** 🔗 =NOTICE REPORT==== 18-Mar-2025::14:10:14.558645 === TLS client: In state connection received SERVER ALERT: Fatal - Certificate Revoked *** System report during emqx_crl_cache_SUITE:t_revoked/1 2025-03-18 14:10:14.558 *** 🔗 =DEBUG REPORT==== 18-Mar-2025::14:10:14.558841 === packet: {mqtt_packet, {mqtt_packet_header,1,false,0,false}, {mqtt_packet_connect,<<"MQTT">>,4,false,true,false,0,false, 60,#{},<<"emqtt-fc8e56a384a0-b7f1b6fd35a2c8cb9ec9">>, undefined,<<>>,<<>>,undefined,<<"******">>}, undefined} reason: closed socket: {ssl_socket,#Port<0.316>, {sslsocket, {gen_tcp,#Port<0.316>,tls_connection,undefined}, [<0.143720.0>,<0.143713.0>]}} msg: send_data_failed clientid: <<"emqtt-fc8e56a384a0-b7f1b6fd35a2c8cb9ec9">> *** System report during emqx_crl_cache_SUITE:t_revoked/1 2025-03-18 14:10:14.559 *** 🔗 =INFO REPORT==== 18-Mar-2025::14:10:14.558991 === reason: closed msg: failed_to_send_connect_packet clientid: <<"emqtt-fc8e56a384a0-b7f1b6fd35a2c8cb9ec9">> ......... *** CT Error Notification 2025-03-18 14:10:16.560 *** 🔗 emqx_crl_cache_SUITE:t_revoked failed on line 905 Reason: {case_clause,{error,connack_timeout}} ```
…_alert`) Similar to emqx#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}; ```
1af3cbf
to
279e51d
Compare
zmstone
reviewed
Sep 5, 2025
@@ -71,7 +71,7 @@ compile_emqx_test_module(M) -> | |||
EmqttDir = code:lib_dir(emqtt), | |||
MFilename= filename:join([EmqxDir, "test", M]), | |||
OutDir = filename:join([EmqttDir, "test"]), | |||
{ok, _} = compile:file(MFilename, [{outdir, OutDir}]), | |||
{{ok, _}, M} = {compile:file(MFilename, [{outdir, OutDir}]), M}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why match M with M ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to known what caused the bad match when it happens
otherwise it's just "{badmatch, error}"
qzhuyan
approved these changes
Sep 5, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
#190
#279
#286