<p dir="ltr">Resending this to avoid the spam filter. It patches rmqs Erlang client to spam way less.</p>
<div class="gmail_quote">---------- Forwarded message ----------<br>From: "Jesper Louis Andersen" <<a href="mailto:jesper.louis.andersen@erlang-solutions.com">jesper.louis.andersen@erlang-solutions.com</a>><br>
Date: Dec 18, 2013 3:15 PM<br>Subject: [PATCH] Make the Erlang RabbitMQ Client shut down gracefully<br>To: "Discussions about RabbitMQ" <<a href="mailto:rabbitmq-discuss@lists.rabbitmq.com">rabbitmq-discuss@lists.rabbitmq.com</a>><br>
Cc: <br><br type="attribution"><div dir="ltr"><div>Hi RMQ developers,</div><div><br></div><div>The following patch changes the behaviour of the RMQ Erlang Client when it shuts down. It avoids spamming the log with death messages in graceful closes. Background is below the patch.</div>
<div><br></div><div>Patch:</div><div><br></div><a href="https://github.com/issuu/amqp_client/commit/2c582c983433027e007b4e80f2c6d9f25d7f854b" target="_blank">https://github.com/issuu/amqp_client/commit/2c582c983433027e007b4e80f2c6d9f25d7f854b</a><div>
<a href="https://github.com/issuu/amqp_client/commit/2c582c983433027e007b4e80f2c6d9f25d7f854b.patch" target="_blank">https://github.com/issuu/amqp_client/commit/2c582c983433027e007b4e80f2c6d9f25d7f854b.patch</a></div><div>
<br></div><div>
Background:</div><div><br></div><div>The RMQ Erlang client holds a supervisor tree which contains processes running as amqp_gen_consumers where a direct_consumer module has been injected. A typical user of the client application will have its own separate supervisor tree. To handle the crash of the client application, the direct_consumer installs a *monitor* on the ConsumerPid. This allows us to stop consumption if the consumer process goes away for some reason.</div>
<div><br></div><div>OTP compliant processes will have two kinds of exit reasons which are graceful: "normal" and "shutdown". The former happens when the ConsumerPid exits normally. Either by calling exit(normal) or by returning from the top-level function. The latter happens if the supervisor decides to close down the tree. It normally sends forth exit(Child, shutdown) in order to shut down its supervisor children processes. Any other exit reason is a grace error.</div>
<div><br></div><div>Implementation:</div><div><br></div><div>The patch detects the two cases of graceful shutdowns and then proceeds to silently close the supervision tree on the RabbitMQ side. This stops such errors from spamming in the logs when the supervisor tree closes down normally. If other errors occur, we close down the tree like we always have, yelling and screaming that something is going very wrong.</div>
<div><br></div><div>Review:</div><div><br></div><div>The patch has seen some internal testing and looks correct; but as I am not too well versed in the supervisor tree, and in particular the supervisor2 structure, I might have introduced a leak. Please look closely at the code with respect to crashing and stopping behaviour in mind. If supervisor2 works anything like supervisor here, it should work.</div>
<div><br></div><div>+++</div><div><br></div><div>I hope the RabbitMQ developers will consider this patch for inclusion as it might help others. It is yours to use and I hereby sign it off as a RabbitMQ contribution.</div>
<div><br></div><div>Merry Christmas :)</div><div></div></div>
</div>