Fixed an infinite loop in viewer connection