Skip to content

Commit 8ba4c84

Browse files
committed
Fix reconfigure server list update and start_client/1 return value
- handle_call({reconfigure, ...}): also update #state.servers when reconfiguring, so that new servers are actually used for sending requests (previously only config was updated, leaving servers empty → no_active_servers) - start_client/1: return the client manager pid instead of the supervisor pid, so callers can pass it directly to eradius_client:send_request/3,4 (previously the supervisor pid was returned, causing send_request to crash with {wanna_send,...} arriving at the supervisor gen_server)
1 parent ee45dae commit 8ba4c84

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

src/eradius_client_mngr.erl

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,16 @@
119119
%%%=========================================================================
120120

121121
%% @doc Start a new RADIUS client that is managed by the eradius applications supervisor tree.
122+
%% Returns the client manager pid (usable with eradius_client:send_request/3,4).
122123
-spec start_client(client_opts()) ->
123124
{ok, pid()} | {error, supervisor:startchild_err()}.
124125
start_client(Opts) ->
125-
eradius_client_top_sup:start_client([Opts]).
126+
case eradius_client_top_sup:start_client([Opts]) of
127+
{ok, SupPid} ->
128+
client_mngr_pid(SupPid);
129+
Error ->
130+
Error
131+
end.
126132

127133
%% @doc Start a new, named RADIUS client that is managed by the eradius applications supervisor tree.
128134
-spec start_client(gen_server:server_name(), client_opts()) ->
@@ -261,8 +267,9 @@ handle_call({failed, _Peer}, _From, State) ->
261267
%% @private
262268
handle_call({reconfigure, Opts}, _From, #state{config = OConfig} = State0) ->
263269
case client_config(maps:merge(OConfig, Opts)) of
264-
{ok, Config} ->
265-
State = reconfigure_address(Config, State0#state{config = Config}),
270+
{ok, #{servers := Servers} = Config} ->
271+
State1 = State0#state{config = Config, servers = Servers},
272+
State = reconfigure_address(Config, State1),
266273
{reply, ok, State};
267274

268275
{error, _} = Error ->
@@ -509,3 +516,11 @@ find_socket_process(PortIdx, Sockets, #state{owner = Owner, config = Config}) ->
509516
Socket ->
510517
{Socket, Sockets}
511518
end.
519+
520+
client_mngr_pid(SupPid) ->
521+
case lists:keyfind(eradius_client_mngr, 1, supervisor:which_children(SupPid)) of
522+
{eradius_client_mngr, Pid, worker, _} when is_pid(Pid) ->
523+
{ok, Pid};
524+
_ ->
525+
{error, not_started}
526+
end.

0 commit comments

Comments
 (0)