Fixed infinite loop if server is shut down