点击立即检查,没有及时更新时间 问题修复

This commit is contained in:
lu7213 committed 2026-11-07 04:21:06 -05:00
1 parent f55f4c2961
commit 68bb68b2b4
2 files changed
+26 -1

No files matched your search

@@ -47,6 +47,7 @@ public class ChainExecutorClient {
private ChainExecutorRuntimeState runtimeState;
private RestTemplate http;
private final AtomicBoolean checking = new AtomicBoolean();
private final Object healthCheckCompletion = new Object();
private volatile boolean reachable;
private volatile boolean checked;
private volatile int consecutiveFailures;
@@ -144,12 +145,16 @@ public class ChainExecutorClient {
log.error("内网链上执行器后台探测异常,后续仍将继续检查,异常类型={}", rootType(failure));
} finally {
checking.set(false);
synchronized (healthCheckCompletion) {
healthCheckCompletion.notifyAll();
}
}
}
/** 页面状态读取同时触发实时探测,“立即检查”不得只返回进程内旧缓存。 */
public Map<String, Object> refreshAvailability() {
monitor();
waitForOngoingCheck();
return availability();
}
@@ -244,6 +249,26 @@ public class ChainExecutorClient {
}
}
/**
* 状态请求撞上后台探测时等待其完成,避免“立即检查”返回探测前的旧时间。
* 最大等待覆盖两次内网HTTP检查的连接与读取超时;中断时保留线程中断标记。
*/
private void waitForOngoingCheck() {
long deadline = System.currentTimeMillis() + 9000L;
synchronized (healthCheckCompletion) {
while (checking.get()) {
long remaining = deadline - System.currentTimeMillis();
if (remaining <= 0) return;
try {
healthCheckCompletion.wait(remaining);
} catch (InterruptedException interrupted) {
Thread.currentThread().interrupt();
return;
}
}
}
}
/**
* 使用独立守护线程执行健康检查,不依赖资源租赁模块是否启用Spring全局调度。
*/