Skip to content

Commit 62c1d35

Browse files
committed
fix: tcp crash when env SSLKEYLOGFILE is set
1 parent 0e9ee35 commit 62c1d35

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/emqtt_bench.erl

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,6 @@ connect(Parent, N, PubSub, Opts) ->
538538
Prometheus = lists:member(prometheus, Opts),
539539
GoSignalPid = proplists:get_value(publish_signal_pid, Opts),
540540
SendGoSignal = proplists:get_value(send_go_signal, Opts),
541-
IsQuic = is_quic(Opts),
542541
MRef = case is_pid(GoSignalPid) of
543542
true -> monitor(process, GoSignalPid);
544543
_ -> undefined
@@ -578,7 +577,7 @@ connect(Parent, N, PubSub, Opts) ->
578577
case ConnRet of
579578
{ok, _Props} ->
580579
inc_counter(Prometheus, connect_succ),
581-
(not IsQuic) andalso maybe_record_keylogfile(Client),
580+
_ = maybe_record_keylogfile(Client, Opts),
582581
Res =
583582
case PubSub of
584583
conn ->
@@ -1552,6 +1551,10 @@ maybe_prefix_payload(Payload, ClientOpts) ->
15521551
is_quic(Opts) ->
15531552
proplists:get_value(quic, Opts) =/= false.
15541553

1554+
-spec is_tls(proplists:proplist()) -> boolean().
1555+
is_tls(Opts) ->
1556+
proplists:get_bool(ssl, Opts).
1557+
15551558
quic_opts_from_arg(Opts)->
15561559
case proplists:get_value(quic, Opts) of
15571560
V when is_boolean(V) ->
@@ -1584,11 +1587,13 @@ prepare_quicer(Opts) ->
15841587
end.
15851588

15861589
%% @doc write SSL keylog file, for Wireshark TLS decryption.
1587-
%% SSL only, doesn't work for other transport
1590+
%% SSL only, doesn't work for other transports
15881591
%% @end
1589-
-spec maybe_record_keylogfile(emqtt:client()) -> ok.
1590-
maybe_record_keylogfile(Client) when is_pid(Client) ->
1591-
do_write_keylogfile(persistent_term:get(sslkeylogfile, false), Client).
1592+
-spec maybe_record_keylogfile(emqtt:client(), proplists:proplist()) -> _.
1593+
maybe_record_keylogfile(Client, Opts) when is_pid(Client) ->
1594+
is_tls(Opts) andalso
1595+
not is_quic(Opts) andalso
1596+
do_write_keylogfile(persistent_term:get(sslkeylogfile, false), Client).
15921597
do_write_keylogfile(false, _Client) ->
15931598
ok;
15941599
do_write_keylogfile(Keylogpath, Client) ->

0 commit comments

Comments
 (0)