<div dir="ltr">Hi,<div><br></div><div>I've got an app that spawn_links processes with trap_exit. I'm killing the linked processes but the monitoring process isn't always receiving the 'EXIT' message.  Here are some code snippets:</div><div><br></div><div>...</div><div>  process_flag(trap_exit, true),</div><div>  link(Connection),</div><div>  link(Channel),</div><div>...</div><div><br></div><div>loop(State) -></div><div>  ...</div><div>  {'EXIT', What, Reason} -></div><div>    do_something_smart();</div><div><br></div><div>  ...<br></div><div><br></div><div>Connection and Channel are a RabbitMQ connection and channel (although that's not necessarily important to know). I'm manually running "force close" on the connection via the RabbitMQ admin interface to trigger the 'EXIT'.  In one case the 'EXIT' message is received and in the other case it isn't. Here are more code snippets to illustrate this (same loop/1 function as above):</div><div><br></div><div>loop(#state{channel=Channel, delay_ack= DelayAck} = State) -></div><div>  ...</div><div><br></div><div>  {#'basic.deliver'{delivery_tag=DeliveryTag}, Content} -></div><div>    ... do something with the content</div><div>    case DelayAck of</div><div>      true -></div><div>        timer:sleep(500), %% allow time for 'EXIT' to arrive in the mailbox before "ack_delivery" message</div><div>        self() ! {ack_delivery, Channel, DeliveryTag},</div><div>        loop(State);</div><div>      _ -></div><div>       amqp_channel:call(Channel, #'basic.ack'{delivery_tag=DeliveryTag}),</div><div>       loop(State)</div><div>    end;</div><div><br></div><div>  {ack_delivery, Channel, DeliveryTag} -></div><div>    timer:sleep(50), %% ack delay</div><div><div>    amqp_channel:call(Channel, #'basic.ack'{delivery_tag=DeliveryTag}),</div><div>    loop(State);</div></div><div><br></div><div>  ...</div><div><br></div><div>In the above snippet DelayAck specifies whether the actual ack happens immediately or as a result of sending another message through loop/1.</div><div>When DelayAck is false the 'EXIT' message is received as expected. When DelayAck is true there is a sleep of 500ms in order to allow the 'EXIT' to arrive in the mailbox before the {ack_delivery, Channel, DeliveryTag} message. But in this case the 'EXIT' message isn't received. The process instead fails with a "noproc" when invoking amqp_channel:call/2 in {ack_delivery...}. This makes sense since the Channel is now invalid, but I did expect 'EXIT' to be received first thereby avoiding this failure.  Increasing the sleep before sending the {ack_delivery...} message doesn't make any difference (except to delay the "noproc" failure). The behavior described in this paragraph is consistent across several test runs.</div><div><br></div><div>What would explain why the 'EXIT' message isn't received (ahead of the ack_delivery message, or even at all) in the DelayAck case?</div><div><br></div><div>Thanks,<br>Rich</div><div><br></div><div><br></div><div><br></div></div>