praekelt/vumi — pull request #734 by jerith (2014-03-04 08:30:22+00:00)
Title: Handle concurrent redis QUITs

Many of our random test failures are `Failure: twisted.internet.error.ConnectionLost: Connection to the other side was lost in a non-clean fashion.`

I suspect this is caused by multiple Redis managers sharing a connection and sending their `QUIT` commands at more or less the same time. If a command is sent after a `QUIT` has been issued but before the server closes the socket, we could be disconnected while the client still has data in the send buffer which will result in the aforementioned exception.

The solution is twofold:
1. We need to wait for `connectionLost` before returning from `TxRedisManager._close()` so that we're sure the connection is completely closed.
2. We need to avoid sending multiple `QUIT` commands to a single connection.

Even if this turns out not to solve the test problems, cleaner shutdown is a good thing in general.