1
0
mirror of synced 2026-04-10 18:48:41 +08:00

Potential fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
Binary Wang
2026-03-21 16:25:44 +08:00
committed by GitHub
parent 8ec7cb8e4b
commit 96f86849f9

View File

@@ -6,6 +6,7 @@ import me.chanjar.weixin.common.bean.WxAccessToken;
import me.chanjar.weixin.common.redis.WxRedisOps;
import org.apache.commons.lang3.StringUtils;
import java.util.concurrent.CancellationException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Lock;
@@ -127,12 +128,31 @@ public abstract class AbstractWxCpInRedisConfigImpl extends WxCpDefaultConfigImp
return expire == null || expire < 2;
} catch (Exception e) {
log.warn("获取access_token过期时间时发生异常将视为已过期以触发刷新异常信息: {}", e.getMessage());
// 清除中断标志确保后续的锁获取和token刷新操作能够正常执行
Thread.interrupted();
// 仅在当前线程已中断且异常为中断相关时,才清除中断标志,避免吞掉上层的中断语义
if (Thread.currentThread().isInterrupted() && isInterruptionRelated(e)) {
Thread.interrupted();
}
return true;
}
}
/**
* 判断异常及其原因链是否为中断相关异常。
*
* @param throwable 异常
* @return 如果异常链中包含 {@link InterruptedException} 或 {@link CancellationException},返回 true否则返回 false
*/
private boolean isInterruptionRelated(Throwable throwable) {
Throwable current = throwable;
while (current != null) {
if (current instanceof InterruptedException || current instanceof CancellationException) {
return true;
}
current = current.getCause();
}
return false;
}
@Override
public void updateAccessToken(WxAccessToken accessToken) {
redisOps.setValue(this.accessTokenKey, accessToken.getAccessToken(), accessToken.getExpiresIn(), TimeUnit.SECONDS);