Fix some crashes in case of connection errors