Skip to content

Commit 15d5e13

Browse files
committed
Merge branch 'maint'
* maint: Set missing link for connection teardown
2 parents f10d416 + 0906e42 commit 15d5e13

File tree

2 files changed

+31
-10
lines changed

2 files changed

+31
-10
lines changed

lib/ssl/src/inet_epmd_tls_socket.erl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,18 @@ connect(
199199
%% ------------------------------------------------------------
200200
start_dist_ctrl(
201201
NetAddress, #sslsocket{payload_sender = DistCtrl} = SslSocket) ->
202+
%% The distribution controller (output controller) needs to be linked
203+
%% to the caller, which becomes the distribution ticker
204+
%% after distribution handshake.
205+
%%
206+
%% net_kernel takes down either the distribution controller
207+
%% or the ticker, but all processes involved in the channel
208+
%% must be taken down when the channel goes down.
209+
%%
210+
%% The SSL socket receiver and payload sender will go down
211+
%% together thanks to their supervisor.
212+
%%
213+
link(DistCtrl),
202214
#hs_data{
203215
socket = DistCtrl,
204216
f_send =

lib/ssl/src/inet_tls_dist.erl

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,18 @@ hs_data_inet_tcp(Driver, Socket) ->
104104
end}.
105105

106106
hs_data_ssl(Family, #sslsocket{payload_sender = DistCtrl} = SslSocket) ->
107+
%% The distribution controller (output controller) needs to be linked
108+
%% to the caller, which becomes the distribution ticker
109+
%% after distribution handshake.
110+
%%
111+
%% net_kernel takes down either the distribution controller
112+
%% or the ticker, but all processes involved in the channel
113+
%% must be taken down when the channel goes down.
114+
%%
115+
%% The SSL socket receiver and payload sender will go down
116+
%% together thanks to their supervisor.
117+
%%
118+
link(DistCtrl),
107119
{ok, Address} =
108120
maybe
109121
{error, einval} ?= ssl:peername(SslSocket),
@@ -513,15 +525,13 @@ do_accept(
513525
Timer = dist_util:start_timer(SetupTime),
514526
{HSData0, NewAllowed} =
515527
case DistSocket of
516-
SslSocket = #sslsocket{payload_sender = Sender} ->
517-
link(Sender),
518-
{hs_data_ssl(Family, SslSocket),
519-
allowed_nodes(SslSocket, Allowed)};
528+
SslSocket = #sslsocket{} ->
529+
HSDataSsl = hs_data_ssl(Family, SslSocket),
530+
{HSDataSsl, allowed_nodes(SslSocket, Allowed)};
520531
PortSocket when is_port(DistSocket) ->
521532
%%% XXX Breaking abstraction barrier
522533
Driver = erlang:port_get_data(PortSocket),
523-
{hs_data_inet_tcp(Driver, PortSocket),
524-
Allowed}
534+
{hs_data_inet_tcp(Driver, PortSocket), Allowed}
525535
end,
526536
HSData =
527537
HSData0#hs_data{
@@ -648,13 +658,14 @@ do_setup(
648658
KTLS = proplists:get_value(ktls, Opts, false),
649659
dist_util:reset_timer(Timer),
650660
maybe
651-
{ok, #sslsocket{connection_handler = Receiver, payload_sender = Sender} = SslSocket} ?=
661+
{ok, SslSocket} ?=
652662
ssl:connect(IP, PortNum, Opts, net_kernel:connecttime()),
653663
HSData =
654664
case KTLS of
655665
true ->
656666
{ok, KtlsInfo} =
657-
ssl_gen_statem:ktls_handover(Receiver),
667+
ssl_gen_statem:ktls_handover(
668+
SslSocket#sslsocket.connection_handler),
658669
Socket = maps:get(socket, KtlsInfo),
659670
case inet_set_ktls(KtlsInfo) of
660671
ok when is_port(Socket) ->
@@ -667,9 +678,7 @@ do_setup(
667678
trace({set_ktls_failed, KtlsReason}))
668679
end;
669680
false ->
670-
_ = monitor_pid(Sender),
671681
ok = ssl:controlling_process(SslSocket, self()),
672-
link(Sender),
673682
hs_data_ssl(Family, SslSocket)
674683
end
675684
#hs_data{

0 commit comments

Comments
 (0)