alibaba / jetcache

JetCache is a Java cache framework.
Apache License 2.0
5.03k stars 1.05k forks source link

RedisLettuceCache 在do_GET 等方法中对于valueDecoder.appyly() 异常没有打印到日志中 #805

Open HHHHHHGGGGGG opened 1 year ago

HHHHHHGGGGGG commented 1 year ago

版本信息:jetcache-starter-redis-lettuce 2.7.3 问题:RedisLettuceCache实现类在do_GET 等方法(比如:do_GET_ALL也有同样的问题)中对于valueDecoder.appyly() 捕获的异常,并没有正确处理,导致打印到日志中异常是redis返回的异常而不是valueDecoder的异常,返回结果中也没有包含对应正常的异常,故导致如果decoder失败,在日志和结果信息中无法获取/看到预期的错误信息。

具体说明如下:

protected CacheGetResult<V> do_GET(K key) {
        try {
            byte[] newKey = buildKey(key);
            RedisFuture<byte[]> future = stringAsyncCommands.get(newKey);
            CacheGetResult<V> result = new CacheGetResult<>(future.handle((valueBytes, ex) -> {
                if (ex != null) {
                    JetCacheExecutor.defaultExecutor().execute(() -> logError("GET", key, ex));
                    return new ResultData(ex);
                } else {
                    try {
                        if (valueBytes != null) {
                            CacheValueHolder<V> holder = (CacheValueHolder<V>) valueDecoder.apply(valueBytes);
                            if (System.currentTimeMillis() >= holder.getExpireTime()) {
                                return new ResultData(CacheResultCode.EXPIRED, null, null);
                            } else {
                                return new ResultData(CacheResultCode.SUCCESS, null, holder);
                            }
                        } else {
                            return new ResultData(CacheResultCode.NOT_EXISTS, null, null);
                        }
                    } catch (Exception exception) {
                        // 问题所在:这里应该处理的异常是 exception,而不是ex,ex是redis client返回的异常
                        logError("GET", key, ex);
                        return new ResultData(ex);
                    }
                }
            }));
            setTimeout(result);
            return result;
        } catch (Exception ex) {
            logError("GET", key, ex);
            return new CacheGetResult(ex);
        }
    }
areyouok commented 1 year ago

你说的对,你要做个PR吗?还是我自己来?

HHHHHHGGGGGG commented 1 year ago

你说的对,你要做个PR吗?还是我自己来?

好的,那我后面提个PR修复一下

Roiocam commented 3 weeks ago

这个 issue 可以 close 了吧