Fix a race condition in the master election.

It was only when stopping the election, so not too major, but still, let's
fix it!
Add some sanity methods to allow blocking methods to check that they're not being called on the libevent thread.
Add a util::SyncTask helper.