Whenever you get a bug report be sure you can reproduce the problem before you start and check youâ€™ve fixed the bug when you make your change.
This advice might seem blindly obvious and youâ€™re probably wondering who on earth would try and fix a bug without reproducing the problem first and then without testing the fix works afterwards . I wondered that too but I was recently involved in a bug report that seemed so cut-and-dried I thought I might have to reconsider my own obsessive desire to stick rigidly to the process. I was of course mistakenâ€¦
A bug showed up in a new message queue processing service that meant when the message queue broker was down for longer than a minute or so the consumer lost its connection and never reconnected in the background. In turn this meant the queue would slowly back-up â€“ the process was still alive and kicking, it just wasnâ€™t servicing the queue.
This bug report came by way of a production incident and an experienced colleague had triaged the problem so the ticket came into the team with some useful details attached. In the ticket the final log message from the service before it went dark told us that the dispatcher thread had shut down due to the failure to reconnect. The ticket also pointed us to the bit of code where the dispatcher thread was configured.
Looking at the service code along with a quick read of the third party library documentation made it seem pretty obvious that the recovery options configured for the dispatcher were insufficient. It was set-up with only 3 short retries and a circuit breaker for good measure. As a result of the incident some monitoring had been added to the queue so there was no reason why we couldnâ€™t just enable infinite connection retries  and effectively disable the circuit breaker. Fixing the dispatcher code was a doddle as the message consumer library is well designed and has good documentation.
It almost seemed too easyâ€¦
The Shortest Path
The problem with bugs in infrastructure code like this is that they almost certainly donâ€™t have any automated test coverage because writing them is really hard . In fact testing this kind of issue can be arduous even when done manually as you need to control the middleware which might be outside your control or just something which sits in the background ticking away and therefore is almost invisible unless you wrote the original code or have had to fix it before. Throw in the fact that the bug wasnâ€™t a showstopper and itâ€™s easy to see how you could apply Sir Tony Hoareâ€™s principle about code â€œbeing so simple there are no obvious bugsâ€ and just push the change out based on the ability to compile the code and the fact that it doesnâ€™t make matters any worse (you can show youâ€™ve not broken the ability to connect to the queue).
Of course when the problem shows up in production again youâ€™ll know that you never really fixed the problem and youâ€™ll have to go around the loop once more, but do what you should have done first time around as the second outage will no doubt have made a few more people annoyed.
Unsurprisingly the simple code change suggested by the ticket actually had no effect at all when we came to test it, and this sudden realisation that we didnâ€™t really understand what was going on was the impetus needed to take a step back and start again from the beginning.
Whilst performing a quick disconnection test (by bouncing the middleware) we noticed that the queue was behaving weirdly and not backing up like it said in the bug report. Another rabbit hole later  and we discover that the queue was not set-up to be durable, which in itself turned out to be another bug.
Eventually we find a way to reproduce the problem and in the process we learn a bit more about how the middleware and message consumer library both work. However we still donâ€™t understand why the new dispatcher configuration does not appear to be working. Luckily the library is open source and so we can debug the issue ourselves and see what is going on under the hood.
The Real Fix
Who would have guessed that internally the message consumer library had another retry and circuit breaker policy that was used to control the (re)connection attempts to the message queue broker. Unlike the dispatcher thread error recovery policy, which was configured explicitly, the message queue connection policy was controlled by a couple of defaulted arguments on the connection configuration object constructor .
Sadly we couldnâ€™t be explicit and use the â€œwait and retry foreverâ€ policy that was available on the dispatcher so instead we had to settle for configurating the number of connection attempts to int.MaxValue.
Naturally it was far simpler to test the fix because we eventually put the effort into working out how to reproduce the problem in the first place. This can be quite significant from a status reporting perspective because it means you are less likely to be over optimistic about your progress. If youâ€™re struggling to reproduce the problem then youâ€™re going to struggle to prove that youâ€™ve fixed it. If you mistakenly believe that the fix is simple and you then feel under pressure to get the testing done at the end itâ€™s harder to convince yourself to do what needs to be done rather than settle for only potentially being right.
 This is somewhat disingenuous as there are times where this is not possible, but thatâ€™s unusual in the world of mainstream software development.
 Without the alert on the queue size we would need to find another way to signal when processing has dropped off. For example the circuit breaker should have triggered some other alert as connection failures are to be expected, but only for a limited time before escalation needs to occur.
 See â€œAutomated Integration Testing with TIBCOâ€ for an example of how Iâ€™ve done this in the past with a TIBCO message queue.
 Yes, the middleware was RabbitMQ but no pun was intended, for once.
 Iâ€™m not suggesting the library, which is provided for free out of kindness, is at fault. On the contrary the documentation was excellent, as was the support we received on Gitter. I need to help fix this, somehow.