summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2024-01-18 14:46:37 +0100
committerLoïc Hoguin <[email protected]>2024-01-18 14:46:37 +0100
commit395618eb84cada02875670aec6c3e8f9d923b1f8 (patch)
treead5754754190e1c8149c16609a33be6621b7a0f5
parent14b96873cf3a9afedeb11f087c5d49f2139665a4 (diff)
downloadct_helper-master.tar.gz
ct_helper-master.tar.bz2
ct_helper-master.zip
Repeat attempts to obtain the remote pidHEADmaster
Sometimes the function would find two pids instead of one, likely due to timing issues related to reusing port numbers. In these cases we retry up to 5 times with a short timeout in between.
-rw-r--r--src/ct_helper.erl16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/ct_helper.erl b/src/ct_helper.erl
index 5659f47..3723095 100644
--- a/src/ct_helper.erl
+++ b/src/ct_helper.erl
@@ -129,14 +129,26 @@ get_parent_pid(Pid) ->
get_remote_pid_tcp(Socket) when is_port(Socket) ->
get_remote_pid_tcp(inet:sockname(Socket));
get_remote_pid_tcp(SockName) ->
+ get_remote_pid_tcp(SockName, 5).
+
+get_remote_pid_tcp(SockName, 0) ->
+ AllPorts = [{P, erlang:port_info(P), (catch inet:peername(P))} || P <- erlang:ports()],
+ error({missing_or_duplicate_ports, SockName, AllPorts});
+get_remote_pid_tcp(SockName, Attempts) ->
AllPorts = [{P, erlang:port_info(P)} || P <- erlang:ports()],
- [Pid] = [
+ Result = [
proplists:get_value(connected, I)
|| {P, I} <- AllPorts,
I =/= undefined,
proplists:get_value(name, I) =:= "tcp_inet",
inet:peername(P) =:= SockName],
- Pid.
+ case Result of
+ [Pid] ->
+ Pid;
+ _ ->
+ timer:sleep(10),
+ get_remote_pid_tcp(SockName, Attempts - 1)
+ end.
%% @doc Find the pid of the remote end of a TLS socket.
%%