Fix crash on socket error and empty history #729