public void close() {
        boolean isUnderlyingConnectionClosed;
        try {
            isUnderlyingConnectionClosed = !conn.isConnected();
        } catch (Exception e) {
            try {
                pool.invalidateObject(this); // XXX should be guarded to happen at most once
            } catch (IllegalStateException ise) {
                // pool is closed, so close the connection
                conn.close();
            } catch (Exception ie) {
                // DO NOTHING the original exception will be rethrown
            }
            throw new RedisException("Cannot close connection (isClosed check failed)");
        }

        if (!isUnderlyingConnectionClosed) {
            // Normal close: underlying connection is still open, so we
            // simply need to return this proxy to the pool
            try {
                pool.returnObject(this); // XXX should be guarded to happen at most once
            } catch (IllegalStateException e) {
                // pool is closed, so close the connection
                conn.close();
            } catch (RuntimeException e) {
                throw e;
            } catch (Exception e) {
                throw new RedisException("Cannot close connection (return to pool failed)", e);
            }
        } else {
            // Abnormal close: underlying connection closed unexpectedly, so we
            // must destroy this proxy
            try {
                pool.invalidateObject(this); // XXX should be guarded to happen at most once
            } catch (IllegalStateException e) {
                // pool is closed, so close the connection
                conn.close();
            } catch (Exception ie) {
                // DO NOTHING, "Already closed" exception thrown below
            }
            throw new RedisException("Already closed.");
        }
    }