fix(task-lock): LLM 响应体补时间界+任务锁跨线程可放与持封顶,掐掉 11 小时无主锁
现网 31888/31856/31725 等任务永久停在 RUNNING,读数链是: java.net.http 的请求超时只封顶到响应头,响应体 read() 走 ArrayBlockingQueue.take(), 上游只发半截就发呆时这一读永久 park(12 条 similar-asin-llm-row 虚拟线程全停在那) ⇒ 无超时的 join() 把 task-queue 线程一起挂住 ⇒ 它手里的 task:similar-asin:<id> 被看门狗无条件续期(实测 11.3 小时,放过留痕 0 次)⇒ 该任务每次结果回传判 40902 (两小时 2370 次),且 12 个 taskQueueExecutor 许可被占满、44 条排队。 两道界各配非零对照: - HttpClientPool.readBodyBounded 把响应体读取挪进一次性虚拟线程、由调用方拿预算去等, 到点中断+关流退成可重试 IOException;三处同型 readResponseBodyBounded 改为委托它。 - LockHandle 直接绑住 HeldLock,任意线程 close 都真放手(旧实现按取锁线程的 ThreadLocal 找锁,跨线程 close 静默 no-op 就是无主锁本体);加持锁封顶 max(30 分钟, 6×TTL), 越界停止续期并 error 留痕,让键在 TTL 内自然过期。 裸跳过例外台账随之清空:它保的正是那条被现网证伪的静默 no-op。 门禁:干净 worktree(HEAD 97312821+本笔)后端全量 4686 例 / 0 红 / 17 skip / rc=0。
This commit is contained in:
+8
-22
@@ -19,10 +19,10 @@ import org.springframework.http.MediaType;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.client.RestClient;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.Duration;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedHashMap;
|
||||
@@ -673,7 +673,7 @@ public class AppearancePatentLlmClient {
|
||||
});
|
||||
request.body(body);
|
||||
String responseText = request.exchange((clientRequest, clientResponse) -> {
|
||||
String responseBody = readResponseBodyBounded(clientResponse.getBody());
|
||||
String responseBody = readResponseBodyBounded(clientResponse.getBody(), attempt);
|
||||
if (!clientResponse.getStatusCode().is2xxSuccessful()) {
|
||||
throw new IllegalStateException("LLM http " + clientResponse.getStatusCode().value()
|
||||
+ ": " + abbreviate(responseBody, 500));
|
||||
@@ -842,26 +842,12 @@ public class AppearancePatentLlmClient {
|
||||
}
|
||||
}
|
||||
|
||||
private String readResponseBodyBounded(InputStream inputStream) throws IOException {
|
||||
if (inputStream == null) {
|
||||
return "";
|
||||
}
|
||||
try (InputStream input = inputStream; ByteArrayOutputStream output = new ByteArrayOutputStream(8192)) {
|
||||
byte[] buffer = new byte[8192];
|
||||
int read;
|
||||
int total = 0;
|
||||
while ((read = input.read(buffer)) != -1) {
|
||||
if (read == 0) {
|
||||
continue;
|
||||
}
|
||||
if ((long) total + read > MAX_LLM_RESPONSE_BYTES) {
|
||||
throw new IOException("LLM response exceeds " + MAX_LLM_RESPONSE_BYTES + " bytes");
|
||||
}
|
||||
output.write(buffer, 0, read);
|
||||
total += read;
|
||||
}
|
||||
return output.toString(StandardCharsets.UTF_8);
|
||||
}
|
||||
/** 响应体读取预算与本次实际用的那套超时对齐;JDK 的超时只到响应头,这一腿原先无界。 */
|
||||
private String readResponseBodyBounded(InputStream inputStream, int attempt) throws IOException {
|
||||
long budget = attempt == 1
|
||||
? Math.min(firstAttemptTimeoutMillis(), Math.max(1, properties.getLlmReadTimeoutMillis()))
|
||||
: Math.max(1, properties.getLlmReadTimeoutMillis());
|
||||
return HttpClientPool.readBodyBounded(inputStream, Duration.ofMillis(budget), MAX_LLM_RESPONSE_BYTES);
|
||||
}
|
||||
|
||||
private JsonNode parseJsonOrThrow(String value) {
|
||||
|
||||
Reference in New Issue
Block a user