Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Potential fix for pull request finding
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
  • Loading branch information
binarywang and Copilot authored Mar 21, 2026
commit 96f86849f957539a090c2e94db0b9bb46a8f34da
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
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;

Expand Down Expand Up @@ -127,12 +128,31 @@ public boolean isAccessTokenExpired() {
return expire == null || expire < 2;
} catch (Exception e) {
log.warn("获取access_token过期时间时发生异常,将视为已过期以触发刷新,异常信息: {}", e.getMessage());
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

log.warn 目前只记录了 e.getMessage(),会丢失堆栈与根因类型信息,后续排查 Redis 中断/连接问题可能不够。建议确认是否需要保留异常对象信息以便定位。

Severity: low

Other Locations
  • weixin-java-cp/src/main/java/me/chanjar/weixin/cp/config/impl/AbstractWxCpInRedisConfigImpl.java:162
  • weixin-java-cp/src/main/java/me/chanjar/weixin/cp/config/impl/AbstractWxCpInRedisConfigImpl.java:199

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.

// 清除中断标志,确保后续的锁获取和token刷新操作能够正常执行
Thread.interrupted();
// 仅在当前线程已中断且异常为中断相关时,才清除中断标志,避免吞掉上层的中断语义
if (Thread.currentThread().isInterrupted() && isInterruptionRelated(e)) {
Thread.interrupted();
}
return true;
}
Comment thread
binarywang marked this conversation as resolved.
}

/**
* 判断异常及其原因链是否为中断相关异常。
*
* @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);
Expand Down