Detecting and handling client disconnect