修复IP归属地查询卡死bug:超时控制+前端AbortController
1. doQueryIpLocation增加单IP总超时5秒(防止4个API依次超时卡死) 2. 单API超时从3-5秒降至2-3秒 3. 批次从3个减为2个(最坏10秒,安全于30秒PHP限制) 4. 前端fetch增加AbortController 15秒超时 5. fetchIpApiWithTimeout默认超时改为3秒
This commit is contained in:
@@ -1064,9 +1064,13 @@ function batchQueryIpLocations(ips) {
|
||||
console.log('[BatchIP] Batch #' + batchNum + ' requesting:', batch);
|
||||
|
||||
const startTime = Date.now();
|
||||
// ★ 前端超时15秒:防止PHP挂起后fetch永远不返回
|
||||
const controller = new AbortController();
|
||||
const abortTimer = setTimeout(() => controller.abort(), 15000);
|
||||
fetch('api/admin.php', {
|
||||
method: 'POST',
|
||||
credentials: 'same-origin',
|
||||
signal: controller.signal,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-Requested-With': 'XMLHttpRequest'
|
||||
@@ -1077,6 +1081,7 @@ function batchQueryIpLocations(ips) {
|
||||
})
|
||||
})
|
||||
.then(r => {
|
||||
clearTimeout(abortTimer);
|
||||
console.log('[BatchIP] Batch #' + batchNum + ' HTTP status:', r.status, 'time:', (Date.now() - startTime) + 'ms');
|
||||
return r.text();
|
||||
})
|
||||
@@ -1097,7 +1102,8 @@ function batchQueryIpLocations(ips) {
|
||||
setTimeout(queryNext, 300);
|
||||
})
|
||||
.catch(e => {
|
||||
console.error('[BatchIP] Batch #' + batchNum + ' fetch error:', e);
|
||||
clearTimeout(abortTimer);
|
||||
console.error('[BatchIP] Batch #' + batchNum + ' fetch error:', e.name === 'AbortError' ? 'TIMEOUT (15s)' : e);
|
||||
setTimeout(queryNext, 300);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user