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

Jesper Louis Andersen jesper.louis.andersen at gmail.com
Wed Dec 18 21:56:52 GMT 2013

Resending this to avoid the spam filter. It patches rmqs Erlang client to
spam way less.
---------- Forwarded message ----------
From: "Jesper Louis Andersen" <jesper.louis.andersen at erlang-solutions.com>
Date: Dec 18, 2013 3:15 PM
Subject: [PATCH] Make the Erlang RabbitMQ Client shut down gracefully
To: "Discussions about RabbitMQ" <rabbitmq-discuss at lists.rabbitmq.com>

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.




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.


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.


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/9915bb66/attachment.html>

More information about the rabbitmq-discuss mailing list