tls: handle the case if endpoint has disconnected