Bugfix: handle connection loss.