File 4502-ssl-fix-process-leak-with-TLS-distribution.patch of Package erlang
From 51c21c404d99b01958a2a41d930b2f14ae74ca8f Mon Sep 17 00:00:00 2001
From: Jakub Witczak <kuba@erlang.org>
Date: Wed, 1 Dec 2021 15:21:53 +0100
Subject: [PATCH] ssl: fix process leak with TLS distribution
- net_kernel could be leaking processes
- if connection process gets killed due to crash propagation
- crash must come from other connection process which
failed on inet_tcp:accept
- see also GH-5332
---
lib/ssl/src/inet_tls_dist.erl | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/lib/ssl/src/inet_tls_dist.erl b/lib/ssl/src/inet_tls_dist.erl
index cddc4f90bf..aa66091267 100644
--- a/lib/ssl/src/inet_tls_dist.erl
+++ b/lib/ssl/src/inet_tls_dist.erl
@@ -444,8 +444,10 @@ gen_accept_connection(
do_accept(
_Driver, AcceptPid, DistCtrl, MyNode, Allowed, SetupTime, Kernel) ->
+ MRef = erlang:monitor(process, AcceptPid),
receive
{AcceptPid, controller} ->
+ erlang:demonitor(MRef, [flush]),
{ok, SslSocket} = tls_sender:dist_tls_socket(DistCtrl),
Timer = dist_util:start_timer(SetupTime),
NewAllowed = allowed_nodes(SslSocket, Allowed),
@@ -463,6 +465,11 @@ do_accept(
{AcceptPid, exit} ->
%% this can happen when connection was initiated, but dropped
%% between TLS handshake completion and dist handshake start
+ ?shutdown2(MyNode, connection_setup_failed);
+ {'DOWN', MRef, _, _, _Reason} ->
+ %% this may happen when connection was initiated, but dropped
+ %% due to crash propagated from other hanshake process which
+ %% failed on inet_tcp:accept (see GH-5332)
?shutdown2(MyNode, connection_setup_failed)
end.
--
2.31.1