Thanks to Pieter for the detective work finding this.
Bug was a deadlock when the process-messages-thread and the IRC thread were adding peer addresses at the same time.
I inspected the code for any other cases where starting a database transaction might trigger this type of bug, and all other cases are OK. I'll keep thinking about how to get the DEBUG_LOCKORDER code to detect this in the future.
Tested by running bitcoind, letting it connect and startup (and join an IRC channel), then shutting it down repeatedly (10 times in a row) and observing no deadlocks.