pma/amqp

channel receiver process leak when caller (channel creator) never exits

xadhoom opened this issue · 6 comments

Hi,

we'have found that if the process that opens a channel never exits, but just calls Channel.close, there's a process leak stuck in AMQP.Channel.Receiver.handle_message/3.

Looking into the code seems that the spawned process (by AMQP.Channel.ReceiverManager.spawn_receiver/2) monitors both the caller and the channel, which is ok. When you call Channel.close, the channel process dies, AMQP.Channel.Receiver.handle_message/3 receives a :DOWN and before exiting calls handle_message/3 again.

The question is why? maybe to get the :DOWN from the caller? other reason? But it never receives any message, so is just stuck there forever...

As proof we have removed the additional handle_message/3 call from the :DOWN processing and everything gets cleaned up correctly.

What do you think?

Side note: in AMQP.Channel.ReceiverManager.spawn_receiver/2 you call Process.monitor(self()). is correct? or maybe you meant Process.monitor(client) ? what is the purpose of monitoring the just spawned process?

ono commented

Nice spot! Working on the fix on this PR. Thank you!

ono commented

Released 1.2.2. Thanks again for the report!

Sorry for going back to this, but looking to the #137 seems that now there's no way for the spawned process to exit. Or I'm missing something?

ono commented

When the process exits its message loop it will be died without an explicit exit call. For example, this is a test when the channel is closed.

Ok, thanks for the clarification!

ono commented

No problem. Thank you so much for the detailed report. It was very helpful!