gotthardp / gen_coap

Generic Erlang CoAP Client/Server
Other
106 stars 47 forks source link

Some processes were leaked after coap request #14

Open wangzhenandy opened 7 years ago

wangzhenandy commented 7 years ago

Hello,

I Found the processes of coap_channel_sup and coap_responder_sup can't be closed after coap request socket closed.

I test it like:

  1. When a client request came, the server creates 4 processes: coap_channel_sup, coap_channel, coap_responder_sup, coap_responder;
  2. Process coap_responder was closed first after finished the request;
  3. Process coap_channel was closed when the client ack timeout;
  4. Processes coap_channel_sup and coap_responder_sup could't closed;
  5. The two processed above will not be reused.

The code in file coap_udp_socker.erl is like: handle_info({terminated, SupPid, ChId}, State=#state{chans=Chans}) -> Chans2 = dict:erase(ChId, Chans), exit(SupPid, normal), {noreply, State#state{chans=Chans2}};

is it right to change it like this? handle_info({terminated, SupPid, ChId}, State=#state{chans=Chans, pool=PoolPid}) -> Chans2 = dict:erase(ChId, Chans), exit(SupPid, normal), coap_channel_sup_sup:delete_channel(PoolPid, ChId), {noreply, State#state{chans=Chans2}};

hejin1026 commented 5 years ago

exit(SupPid, normal) but SupPid(coap_channel_sup) can not exit because

If Reason is the atom normal, Pid does not exit. If it is trapping exits, the exit signal is transformed into a message {'EXIT', From, normal} and delivered to its message queue.

so why use exit(SupPid, normal), it not work exit(SupPid, kill) and coap_channel_sup_sup:delete_channel(PoolPid, ChId) can make SupPid shutdown is that right?