Unhandled exception prevented demoting the primary. In addition to that wrap the update_leader call in the HA loop into try..except block and implement a test case. Fixes https://github.com/zalando/patroni/issues/1684