File 0744-Fix-ct_gen_conn-connection-registration-race.patch of Package erlang

From 4ad9e72ba868d446eec8cb5fd4965279ffed6810 Mon Sep 17 00:00:00 2001
From: Anders Svensson <anders@erlang.org>
Date: Thu, 1 Apr 2021 11:33:58 +0200
Subject: [PATCH 1/4] Fix ct_gen_conn connection registration race

Module ct_netconfc (and more) creates transport connections in callbacks
from the process started by ct_gen_conn:start/4. The process pid is
written to a table in ct_util, but inserting and deleting entries took
place in different processes: insert from the calling process, delete
from the started process. As a result, a quick error from the underlying
transport (ssh in the case of ct_netconfc) could result in the
ct_gen_conn process deleting its entry and exiting before the calling
process had written it, which orphaned the entry in the table and lead
to errors from subsequent calls to ct_gen_conn. In particular, start/4
returned the pid of the dead process.

Move insert into the started process to avoid the race.
---
 lib/common_test/src/ct_gen_conn.erl | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/lib/common_test/src/ct_gen_conn.erl b/lib/common_test/src/ct_gen_conn.erl
index 1ab9946d96..f4f002614e 100644
--- a/lib/common_test/src/ct_gen_conn.erl
+++ b/lib/common_test/src/ct_gen_conn.erl
@@ -235,9 +235,6 @@ do_start(Opts) ->
     receive
 	{connected,Pid} ->
 	    erlang:demonitor(MRef, [flush]),
-	    ct_util:register_connection(Opts#gen_opts.name,
-					Opts#gen_opts.address,
-					Opts#gen_opts.callback, Pid),
 	    {ok,Pid};
 	{Error,Pid} ->
 	    receive {'DOWN',MRef,process,_,_} -> ok end,
@@ -308,6 +305,10 @@ init_gen(Parent,Opts) ->
 	    put(conn_pid,ConnPid),
 	    CtUtilServer = whereis(ct_util_server),
 	    link(CtUtilServer),
+	    ct_util:register_connection(Opts#gen_opts.name,
+					Opts#gen_opts.address,
+					Opts#gen_opts.callback,
+                                        self()),
 	    Parent ! {connected,self()},
 	    loop(Opts#gen_opts{conn_pid=ConnPid,
 			       cb_state=State,
-- 
2.26.2

openSUSE Build Service is sponsored by