close socket on onClose event in SecureAgent