Skip to content

Commit

Permalink
Fix the value passed into the Name parameter of the subchannel gproc_…
Browse files Browse the repository at this point in the history
…pool disconnect_worker and remove_worker functions
  • Loading branch information
heshaoqiong committed Mar 23, 2023
1 parent a5aa6e9 commit 21a41ff
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions src/grpcbox_subchannel.erl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
ready/3,
disconnected/3]).

-record(data, {endpoint :: grpcbox_channel:endpoint(),
-record(data, {name :: any(),
endpoint :: grpcbox_channel:endpoint(),
channel :: grpcbox_channel:t(),
info :: #{authority := binary(),
scheme := binary(),
Expand All @@ -41,8 +42,10 @@ stop(Pid, Reason) ->

init([Name, Channel, Endpoint, Encoding, StatsHandler]) ->
process_flag(trap_exit, true),

gproc_pool:connect_worker(Channel, Name),
{ok, disconnected, #data{conn=undefined,
{ok, disconnected, #data{name=Name,
conn=undefined,
info=info_map(Endpoint, Encoding, StatsHandler),
endpoint=Endpoint,
channel=Channel}}.
Expand Down Expand Up @@ -89,24 +92,24 @@ handle_event(_, _, _) ->
keep_state_and_data.

terminate(_Reason, _State, #data{conn=undefined,
endpoint=Endpoint,
name=Name,
channel=Channel}) ->
gproc_pool:disconnect_worker(Channel, Endpoint),
gproc_pool:remove_worker(Channel, Endpoint),
gproc_pool:disconnect_worker(Channel, Name),
gproc_pool:remove_worker(Channel, Name),
ok;
terminate(normal, _State, #data{conn=Pid,
endpoint=Endpoint,
name=Name,
channel=Channel}) ->
h2_connection:stop(Pid),
gproc_pool:disconnect_worker(Channel, Endpoint),
gproc_pool:remove_worker(Channel, Endpoint),
gproc_pool:disconnect_worker(Channel, Name),
gproc_pool:remove_worker(Channel, Name),
ok;
terminate(Reason, _State, #data{conn=Pid,
endpoint=Endpoint,
name=Name,
channel=Channel}) ->
gproc_pool:disconnect_worker(Channel, Name),
gproc_pool:remove_worker(Channel, Name),
exit(Pid, Reason),
gproc_pool:disconnect_worker(Channel, Endpoint),
gproc_pool:remove_worker(Channel, Endpoint),
ok.

connect(Data=#data{conn=undefined,
Expand Down

0 comments on commit 21a41ff

Please sign in to comment.