feat(retry): B24 冷却扩围到「不回包/解密失败成片」两形
连接层冷却只认「会话没建立」,而现网 B26 的成片失败是连接已建立的两种形状: 对端在给出响应前收连接、HTTP 200 里行级结论带解密失败。给冷却表加第二条 证据道(同 host 分格、同窗长、同阈值 2),品牌客户端把两形都记进这条道: 不回包按异常即时记证;解密形状先批内开票,批终态只在零可结算结论时按票 记证——一枚干净结论就整票作废,脏品牌名的行级差异证据面保持不变。 冷却期快失败沿用既有整批分支,归因文案单独一条以便交付侧与取证区分。
This commit is contained in:
+100
-3
@@ -72,6 +72,27 @@ public class BrandCheckClient {
|
||||
private static final int CONNECT_FAILURE_EVIDENCE = 2;
|
||||
private static final String REASON_SERVICE_UNREACHABLE = "品牌检测服务不可达(连接未建立,非本行数据问题)";
|
||||
|
||||
/**
|
||||
* 「连上了但不回包」的形状指纹(B24 扩围,2026-10-26 拍板):JDK HttpClient 在对端
|
||||
* 给出响应前关闭连接时抛的两句原文(2026-10-24 现网 B→A:16890 87/88 条是前者)。
|
||||
* 读超时不算——那仍是"慢",2026-10-24 立账时按口径故意留在重试有意义的一侧。
|
||||
*/
|
||||
private static final java.util.regex.Pattern PEER_CLOSED_WITHOUT_RESPONSE =
|
||||
java.util.regex.Pattern.compile("header parser received no bytes|EOF reached while reading");
|
||||
|
||||
/**
|
||||
* 「解密失败成片」的形状指纹:16890 侧解密/JSON 解析失败的行级 reason(现网三形——
|
||||
* {@code 查询或解密失败: …Malformed UTF-8 data}/{@code Expecting value: line 1 column 1}
|
||||
* /三层嵌套的旧版 {@code 解密失败:} 前缀,见 BACKLOG B26)。
|
||||
*/
|
||||
private static final java.util.regex.Pattern DECRYPT_FAILURE_REASON =
|
||||
java.util.regex.Pattern.compile("解密失败|Expecting value");
|
||||
|
||||
/** no-answer 道的解密失败条数:与 connect 道同数字,两次同形且整批零干净结论才是服务在掉。 */
|
||||
private static final int NO_ANSWER_FAILURE_EVIDENCE = 2;
|
||||
private static final String REASON_SERVICE_DEGRADED =
|
||||
"品牌检测服务不可达(解密链路成片失败,非本行数据问题)";
|
||||
|
||||
/**
|
||||
* 代理出口被上游拒绝的证据条数:同一批里已有这么多个品牌在换过出口后仍被拒,
|
||||
* 后面的品牌不再发起首轮探针。2026-10-23 现网:16890 每个品牌最多换 2 个 IP,
|
||||
@@ -301,7 +322,7 @@ public class BrandCheckClient {
|
||||
return outcomes;
|
||||
}
|
||||
long cooldownMillis = Math.max(0, properties.getUnreachableCooldownMillis());
|
||||
if (unreachableCooldown.isCoolingDown(properties.getBaseUrl(), cooldownMillis)) {
|
||||
if (unreachableCooldown.connectLaneCooling(properties.getBaseUrl(), cooldownMillis)) {
|
||||
// 客户端级冷却(B24):上一批已确认连接层不可达,本批连首轮探针都不发。
|
||||
// 结论与批内短路版逐字一致(每行仍判查询失败、reason 同文案),差别只是不再为
|
||||
// "确认还是断的"每批各烧一轮连接探针;到期后下一批的真实请求兼作探针。
|
||||
@@ -312,6 +333,17 @@ public class BrandCheckClient {
|
||||
}
|
||||
return outcomes;
|
||||
}
|
||||
if (unreachableCooldown.noAnswerLaneCooling(properties.getBaseUrl(), cooldownMillis)) {
|
||||
// B24 扩围(2026-10-26 拍板):上一批已确认「连上了但不回包」或「解密链路成片失败」,
|
||||
// 本批同样一个请求都不发。行级结论不变(每品牌仍判查询失败),只是归因从空 reason/
|
||||
// 逐行白等 45~65 秒,换成一条可运维的服务级降级文案;到期后下一批的真实请求兼作探针。
|
||||
log.warn("[brand-check] NO_ANSWER_COOLDOWN 客户端级冷却中(不回包/解密成片),整批不打上游"
|
||||
+ " brands={} window={}ms", brands.size(), cooldownMillis);
|
||||
for (String brand : brands) {
|
||||
outcomes.put(brand, new BrandCheckOutcome(List.of(), List.of(brand), REASON_SERVICE_DEGRADED));
|
||||
}
|
||||
return outcomes;
|
||||
}
|
||||
long firstAttemptDeadlineNanos = deadlineNanos == Long.MAX_VALUE
|
||||
? Long.MAX_VALUE
|
||||
: deadlineNanos + FIRST_ATTEMPT_QUEUE_GRACE_MILLIS * 1_000_000L;
|
||||
@@ -325,6 +357,9 @@ public class BrandCheckClient {
|
||||
AtomicInteger connectFailures = new AtomicInteger();
|
||||
// 出口被上游拒绝的证据跨品牌累计:达到阈值后不再给后续品牌发首轮探针。
|
||||
AtomicInteger egressRejections = new AtomicInteger();
|
||||
// no-answer 道的解密形状批内计数(B24 扩围):批终态才记证,见 awaitOutcome 循环后的聚合。
|
||||
AtomicInteger decryptFailures = new AtomicInteger();
|
||||
AtomicBoolean sawCleanConclusion = new AtomicBoolean(false);
|
||||
for (String brand : brands) {
|
||||
AtomicBoolean started = new AtomicBoolean(false);
|
||||
AtomicBoolean rejected = new AtomicBoolean(false);
|
||||
@@ -335,7 +370,8 @@ public class BrandCheckClient {
|
||||
() -> {
|
||||
started.set(true);
|
||||
return checkOneBrand(brand, strategy, deadlineNanos, upstreamRejecting,
|
||||
proxyUrl, userId, connectFailures, egressRejections);
|
||||
proxyUrl, userId, connectFailures, egressRejections,
|
||||
decryptFailures, sawCleanConclusion);
|
||||
},
|
||||
checkExecutor);
|
||||
} finally {
|
||||
@@ -355,6 +391,20 @@ public class BrandCheckClient {
|
||||
outcomes.put(brands.get(index), awaitOutcome(brands.get(index), futures.get(index),
|
||||
startedFlags.get(index), deadlineNanos, firstAttemptDeadlineNanos));
|
||||
}
|
||||
// 批终态才动 no-answer 表(B24 扩围):一枚可结算结论就整票作废并清零,
|
||||
// 零干净的批次按票数逐条记证(阈值 2 与 connect 道同数字)。本批请求不受影响——
|
||||
// 冷却只掐后续批次,行级差异的证据面一字不动。
|
||||
if (sawCleanConclusion.get()) {
|
||||
unreachableCooldown.clearNoAnswerEvidence(properties.getBaseUrl());
|
||||
} else {
|
||||
for (int i = 0; i < decryptFailures.get(); i++) {
|
||||
if (unreachableCooldown.recordNoAnswerFailure(properties.getBaseUrl(), cooldownMillis)) {
|
||||
log.warn("[brand-check] NO_ANSWER_COOLDOWN 批内解密失败 {} 枚且零干净结论,"
|
||||
+ "进入客户端级冷却 {}ms host={}",
|
||||
decryptFailures.get(), cooldownMillis, properties.getBaseUrl());
|
||||
}
|
||||
}
|
||||
}
|
||||
return outcomes;
|
||||
}
|
||||
|
||||
@@ -366,7 +416,9 @@ public class BrandCheckClient {
|
||||
private BrandCheckOutcome checkOneBrand(String brand, String strategy, long deadlineNanos,
|
||||
AtomicBoolean upstreamRejecting, String proxyUrl, Long userId,
|
||||
AtomicInteger connectFailures,
|
||||
AtomicInteger egressRejections) {
|
||||
AtomicInteger egressRejections,
|
||||
AtomicInteger decryptFailures,
|
||||
AtomicBoolean sawCleanConclusion) {
|
||||
int attempts = Math.max(1, properties.getRetryTimes());
|
||||
BrandCheckResponse response = null;
|
||||
Exception lastFailure = null;
|
||||
@@ -428,6 +480,12 @@ public class BrandCheckClient {
|
||||
CONNECT_FAILURE_EVIDENCE, brand, attempt, attempts, ex.getMessage());
|
||||
break;
|
||||
}
|
||||
} else if (isPeerClosedWithoutResponse(ex)) {
|
||||
// 连上了、对端却在给出响应前把连接收了(B26 主形 header parser received no
|
||||
// bytes):重试救不回这一形状,按 no-answer 道即时记证;本品牌照旧重试收尾。
|
||||
log.warn("[brand-check] NO_ANSWER 对端在给出响应前关闭连接 brand={} attempt={}/{} err={}",
|
||||
brand, attempt, attempts, ex.getMessage());
|
||||
recordNoAnswerFailure();
|
||||
} else {
|
||||
// 连上了只是这次没答好(读超时/解析失败):连接层证据不作数
|
||||
connectFailures.set(0);
|
||||
@@ -444,6 +502,14 @@ public class BrandCheckClient {
|
||||
// 拿到响应=连接是通的,证据清零,别跨到下一次真断连时凑数
|
||||
connectFailures.set(0);
|
||||
unreachableCooldown.recordConnected(properties.getBaseUrl());
|
||||
if (response != null && !nullToEmpty(response.getQueryFaildData()).isEmpty()
|
||||
&& isDecryptFailure(response.getReason())) {
|
||||
// 解密形状(B26 成片主形):先计一条批内票;是否在服务级记证由批终态聚合决定
|
||||
// ——同批里只要有一枚可结算结论,就认定这是本行数据问题而不是服务在掉。
|
||||
decryptFailures.incrementAndGet();
|
||||
} else if (response != null) {
|
||||
sawCleanConclusion.set(true);
|
||||
}
|
||||
if (response != null && nullToEmpty(response.getQueryFaildData()).isEmpty()) {
|
||||
// 本次查询完成且无失败项:命中侵权(faild_data)属有效结论,不重试。
|
||||
return new BrandCheckOutcome(nullToEmpty(response.getFaildData()), List.of(), "");
|
||||
@@ -632,6 +698,37 @@ public class BrandCheckClient {
|
||||
}
|
||||
}
|
||||
|
||||
/** no-answer 道即时记证(不回包形状):达到阈值的那一方打进入冷却的 warn(B24 扩围)。 */
|
||||
private void recordNoAnswerFailure() {
|
||||
long cooldownMillis = Math.max(0, properties.getUnreachableCooldownMillis());
|
||||
if (unreachableCooldown.recordNoAnswerFailure(properties.getBaseUrl(), cooldownMillis)) {
|
||||
log.warn("[brand-check] NO_ANSWER_COOLDOWN 不回包证据累计到阈值,进入客户端级冷却 {}ms host={}",
|
||||
cooldownMillis, properties.getBaseUrl());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 「连上了但对端在给出响应前关闭连接」(B24 扩围):顺着 cause 链认
|
||||
* {@link #PEER_CLOSED_WITHOUT_RESPONSE} 那两句 JDK HttpClient 原文。
|
||||
* 与 {@link #isConnectFailure} 互斥(会话没建立的形状归连接道),读超时不算——
|
||||
* 那侧注释在 B19 就写死了:慢≠掉。
|
||||
*/
|
||||
static boolean isPeerClosedWithoutResponse(Throwable error) {
|
||||
for (Throwable t = error; t != null && t != t.getCause(); t = t.getCause()) {
|
||||
String message = t.getMessage();
|
||||
if (message != null && PEER_CLOSED_WITHOUT_RESPONSE.matcher(message).find()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/** 「解密链路失败」的行级 reason(B24 扩围):上游已回话、内容解不开,供批终态聚合判定。 */
|
||||
static boolean isDecryptFailure(String reason) {
|
||||
String trimmed = reason == null ? "" : reason.trim();
|
||||
return !trimmed.isEmpty() && DECRYPT_FAILURE_REASON.matcher(trimmed).find();
|
||||
}
|
||||
|
||||
/**
|
||||
* 连接层判定下沉 {@code UnreachableCooldown.isConnectFailure}(B24):判定口径与
|
||||
* 两个 LLM 客户端共用一份,不再各留包内副本。
|
||||
|
||||
Reference in New Issue
Block a user