Much-needed cleanup for connection failure handling (fix #451)