File 0182-Set-missing-link-for-connection-teardown.patch of Package erlang
From 4b05062254b15f38e5e0b157e8bf116f73d0b2be Mon Sep 17 00:00:00 2001
From: Raimo Niskanen <raimo@erlang.org>
Date: Wed, 17 Sep 2025 18:11:50 +0200
Subject: [PATCH] Set missing link for connection teardown
---
lib/ssl/src/inet_epmd_tls_socket.erl | 12 ++++++++++++
lib/ssl/src/inet_tls_dist.erl | 29 ++++++++++++++++++----------
2 files changed, 31 insertions(+), 10 deletions(-)
diff --git a/lib/ssl/src/inet_epmd_tls_socket.erl b/lib/ssl/src/inet_epmd_tls_socket.erl
index 619d0ee21c..fbc84ab82b 100644
--- a/lib/ssl/src/inet_epmd_tls_socket.erl
+++ b/lib/ssl/src/inet_epmd_tls_socket.erl
@@ -199,6 +199,18 @@ connect(
%% ------------------------------------------------------------
start_dist_ctrl(
NetAddress, #sslsocket{payload_sender = DistCtrl} = SslSocket) ->
+ %% The distribution controller (output controller) needs to be linked
+ %% to the caller, which becomes the distribution ticker
+ %% after distribution handshake.
+ %%
+ %% net_kernel takes down either the distribution controller
+ %% or the ticker, but all processes involved in the channel
+ %% must be taken down when the channel goes down.
+ %%
+ %% The SSL socket receiver and payload sender will go down
+ %% together thanks to their supervisor.
+ %%
+ link(DistCtrl),
#hs_data{
socket = DistCtrl,
f_send =
diff --git a/lib/ssl/src/inet_tls_dist.erl b/lib/ssl/src/inet_tls_dist.erl
index 46d1193a05..2cda800a12 100644
--- a/lib/ssl/src/inet_tls_dist.erl
+++ b/lib/ssl/src/inet_tls_dist.erl
@@ -104,6 +104,18 @@ hs_data_inet_tcp(Driver, Socket) ->
end}.
hs_data_ssl(Family, #sslsocket{payload_sender = DistCtrl} = SslSocket) ->
+ %% The distribution controller (output controller) needs to be linked
+ %% to the caller, which becomes the distribution ticker
+ %% after distribution handshake.
+ %%
+ %% net_kernel takes down either the distribution controller
+ %% or the ticker, but all processes involved in the channel
+ %% must be taken down when the channel goes down.
+ %%
+ %% The SSL socket receiver and payload sender will go down
+ %% together thanks to their supervisor.
+ %%
+ link(DistCtrl),
{ok, Address} =
maybe
{error, einval} ?= ssl:peername(SslSocket),
@@ -513,15 +525,13 @@ do_accept(
Timer = dist_util:start_timer(SetupTime),
{HSData0, NewAllowed} =
case DistSocket of
- SslSocket = #sslsocket{payload_sender = Sender} ->
- link(Sender),
- {hs_data_ssl(Family, SslSocket),
- allowed_nodes(SslSocket, Allowed)};
+ SslSocket = #sslsocket{} ->
+ HSDataSsl = hs_data_ssl(Family, SslSocket),
+ {HSDataSsl, allowed_nodes(SslSocket, Allowed)};
PortSocket when is_port(DistSocket) ->
%%% XXX Breaking abstraction barrier
Driver = erlang:port_get_data(PortSocket),
- {hs_data_inet_tcp(Driver, PortSocket),
- Allowed}
+ {hs_data_inet_tcp(Driver, PortSocket), Allowed}
end,
HSData =
HSData0#hs_data{
@@ -648,13 +658,14 @@ do_setup(
KTLS = proplists:get_value(ktls, Opts, false),
dist_util:reset_timer(Timer),
maybe
- {ok, #sslsocket{connection_handler = Receiver, payload_sender = Sender} = SslSocket} ?=
+ {ok, SslSocket} ?=
ssl:connect(IP, PortNum, Opts, net_kernel:connecttime()),
HSData =
case KTLS of
true ->
{ok, KtlsInfo} =
- ssl_gen_statem:ktls_handover(Receiver),
+ ssl_gen_statem:ktls_handover(
+ SslSocket#sslsocket.connection_handler),
Socket = maps:get(socket, KtlsInfo),
case inet_set_ktls(KtlsInfo) of
ok when is_port(Socket) ->
@@ -667,9 +678,7 @@ do_setup(
trace({set_ktls_failed, KtlsReason}))
end;
false ->
- _ = monitor_pid(Sender),
ok = ssl:controlling_process(SslSocket, self()),
- link(Sender),
hs_data_ssl(Family, SslSocket)
end
#hs_data{
--
2.51.0