jlouis / turtle

A wrapper on the RabbitMQ Erlang Client (Erlang)
Other
71 stars 15 forks source link

Handle Conns/Chans/Consumers through a janitor process #33

Closed jlouis closed 7 years ago

jlouis commented 7 years ago

In the official RabbitMQ AMQP client, there is no concept of a controlling process common in Erlang systems. Thus, if you create a Connection, a Channel or a Consumer, there is no guarantee that it will be closed if the process creating it goes away.

In other words: you have to treat those resources as unmanaged and handle them accordingly.

Turtle currently does not manage resources at all. This leads to situations in which channels and consumers end up in a "limbo" state:

In this situation, the messages is seen as delivered and they are then being "processed" by the client. But since they are gone, they are unlikely to ever be acked, unless one issues a faulty bulk-ack or bulk-reject by accident. Everything is dire.

This PR introduces a new gen_server in turtle called the janitor. The responsibility of the janitor is to keep track of resources and monitor processes. If a process goes away, the resources belonging to that process is also going to go away since the janitor will clean up.

Now, the only process which needs to trap exits is the janitor. And a lot of nasty termination paths can be removed from turtle. In short, we'll get a far more stable version of turtle. The downside is that this is a backwards compatibility breaking change.

jlouis commented 7 years ago

Looks like we might have killed the problems with test case nonedeterminism by fixing this as well.