added a check for @conn.connectionState before invoking it, for tests