[rabbitmq-discuss] Linking to a channel process (erlang client)

Matthew Sackman matthew at rabbitmq.com
Wed Jun 15 00:45:34 BST 2011


On Tue, Jun 14, 2011 at 06:22:41PM +0100, Hunter Morris wrote:
> I have a similar application to Erik which supervises a connection via
> a worker and creates a channel per application worker process so that
> channel exceptions kill only worker processes and the entire
> supervision tree is torn down by a connection exception. In general
> this works brilliantly well. However, on rare but possible occasions,
> the following happens when a worker process opens a channel:
> 
>     {ok, ChanPid} = amqp_connection:open_channel(ConnPid),
>     % self() dies due to exit signal from another linked process
>     link(ChanPid), % we never get here due to exit race
> 
> Unfortunately, this leaves a "hanging chad" channel in the supervision
> tree. Am I missing something subtle? Is it possible to avoid such a
> race?

Hmm, that's tricky. Depends what you want to do really - you could have
the supervisor link to the base process that is the amqp_client
application if you want (before starting any workers), but it depends if
you want death of your application to tear down the whole client -
sequencing of those actions to achieve a safe, controlled shutdown, is
not trivial.

My understanding is that on the whole, libraries that spawn processes
are linked to, or monitored, rather than linking / monitoring their
clients. However, this may be wrong and/or not best practise. If you
have ideas how this can be improved, please do let us know.

Best wishes,

Matthew


More information about the rabbitmq-discuss mailing list