[rabbitmq-discuss] [PATCH] Make the Erlang RabbitMQ Client shut down gracefully

Jesper Louis Andersen jesper.louis.andersen at erlang-solutions.com
Wed Dec 18 14:15:18 GMT 2013


Hi RMQ developers,

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.

Patch:

https://github.com/issuu/amqp_client/commit/2c582c983433027e007b4e80f2c6d9f25d7f854b
https://github.com/issuu/amqp_client/commit/2c582c983433027e007b4e80f2c6d9f25d7f854b.patch

Background:

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.

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.

Implementation:

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.

Review:

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.

+++

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.

Merry Christmas :)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rabbitmq.com/pipermail/rabbitmq-discuss/attachments/20131218/d6c7b29c/attachment.html>


More information about the rabbitmq-discuss mailing list