What's life cycyle about a channel on server side

Hi,
I have a question about channel lifecycle management.
If i write such code in js client.
var chan1 = socket.channel(“room:1”, {})
var chan2 = socket.channel(“room:2”, {})
var chan3 = socket.channel(“room:3”, {})
From my understanding, the service will create three process to handle different channels.
If i leave these channel in clients, will the server close all the chnnale process since they are not used anymore.
Or Should I close the change manually?

1 Like

You’re right - once you join a channel, a new process is started on the server and the join/3 callback (https://hexdocs.pm/phoenix/Phoenix.Channel.html#c:join/3) is executed.

You don’t have to do anything to close the channel manually on the server-side. The process exits automatically when the client disconnects. In such case, a terminate/2 callback is executed if you want to do some cleaning up (but you don’t have to do this) - https://hexdocs.pm/phoenix/Phoenix.Channel.html#module-terminate

I hope this answers your question :slight_smile:

3 Likes

Very clear explaination. Thanks a lots.

2 Likes