修复: SSL降级触发条件优化-任何连接异常都计数;任务间随机延迟从2-4秒增加到4-6秒;增加SSL计数器在POST最终失败时
This commit is contained in:
@@ -474,18 +474,16 @@ public class WebManager {
|
|||||||
plugin.getLogger().warning("[Web通信] GET HTTP " + resp.statusCode() + ": " + shortUrl + " | 响应: " + shortBody);
|
plugin.getLogger().warning("[Web通信] GET HTTP " + resp.statusCode() + ": " + shortUrl + " | 响应: " + shortBody);
|
||||||
return null;
|
return null;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// ★ SSL断路器:跟踪连续失败
|
// ★ SSL断路器:跟踪连续失败(所有连接异常都计数)
|
||||||
if (e.getMessage() != null && e.getMessage().contains("handshake")) {
|
sslConsecutiveFailures++;
|
||||||
sslConsecutiveFailures++;
|
// ★ 降级到HTTP:连续失败3次
|
||||||
// ★ 降级到HTTP:连续失败3次
|
if (sslConsecutiveFailures >= SSL_DOWNGRADE_THRESHOLD && shouldDowngradeToHttp(urlStr)) {
|
||||||
if (sslConsecutiveFailures >= SSL_DOWNGRADE_THRESHOLD && shouldDowngradeToHttp(urlStr)) {
|
String httpUrl = urlStr.replaceFirst("^https:", "http:");
|
||||||
String httpUrl = urlStr.replaceFirst("^https:", "http:");
|
return doGetHttpFallback(httpUrl);
|
||||||
return doGetHttpFallback(httpUrl);
|
}
|
||||||
}
|
if (sslConsecutiveFailures >= SSL_CIRCUIT_THRESHOLD) {
|
||||||
if (sslConsecutiveFailures >= SSL_CIRCUIT_THRESHOLD) {
|
sslCircuitOpenUntil = System.currentTimeMillis() + SSL_CIRCUIT_COOLDOWN_MS;
|
||||||
sslCircuitOpenUntil = System.currentTimeMillis() + SSL_CIRCUIT_COOLDOWN_MS;
|
plugin.getLogger().warning("[Web通信] SSL断路器触发: 连续失败" + sslConsecutiveFailures + "次,暂停轮询60秒");
|
||||||
plugin.getLogger().warning("[Web通信] SSL断路器触发: 连续失败" + sslConsecutiveFailures + "次,暂停轮询60秒");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
plugin.getLogger().warning("[Web通信] GET异常: " + e.getClass().getSimpleName() + ": " + e.getMessage());
|
plugin.getLogger().warning("[Web通信] GET异常: " + e.getClass().getSimpleName() + ": " + e.getMessage());
|
||||||
return null;
|
return null;
|
||||||
@@ -555,6 +553,8 @@ public class WebManager {
|
|||||||
plugin.getLogger().warning("[Web通信] POST HTTP " + resp.statusCode() + ": " + shortUrl + " | 响应: " + shortBody);
|
plugin.getLogger().warning("[Web通信] POST HTTP " + resp.statusCode() + ": " + shortUrl + " | 响应: " + shortBody);
|
||||||
return null;
|
return null;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
// ★ SSL断路器:跟踪连续失败(所有连接异常都计数)
|
||||||
|
sslConsecutiveFailures++;
|
||||||
plugin.getLogger().warning("[Web通信] POST异常: " + e.getClass().getSimpleName() + ": " + e.getMessage());
|
plugin.getLogger().warning("[Web通信] POST异常: " + e.getClass().getSimpleName() + ": " + e.getMessage());
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -593,18 +593,16 @@ public class WebManager {
|
|||||||
plugin.getLogger().warning("[Web通信] POST HTTP " + resp.statusCode() + ": " + shortUrl + " | 响应: " + shortBody);
|
plugin.getLogger().warning("[Web通信] POST HTTP " + resp.statusCode() + ": " + shortUrl + " | 响应: " + shortBody);
|
||||||
return null;
|
return null;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// ★ SSL断路器:跟踪连续失败
|
// ★ SSL断路器:跟踪连续失败(所有连接异常都计数)
|
||||||
if (e.getMessage() != null && e.getMessage().contains("handshake")) {
|
sslConsecutiveFailures++;
|
||||||
sslConsecutiveFailures++;
|
// ★ 降级到HTTP:连续失败3次
|
||||||
// ★ 降级到HTTP:连续失败3次
|
if (sslConsecutiveFailures >= SSL_DOWNGRADE_THRESHOLD && shouldDowngradeToHttp(urlStr)) {
|
||||||
if (sslConsecutiveFailures >= SSL_DOWNGRADE_THRESHOLD && shouldDowngradeToHttp(urlStr)) {
|
String httpUrl = urlStr.replaceFirst("^https:", "http:");
|
||||||
String httpUrl = urlStr.replaceFirst("^https:", "http:");
|
return doPostHttpFallback(httpUrl, jsonBody);
|
||||||
return doPostHttpFallback(httpUrl, jsonBody);
|
}
|
||||||
}
|
if (sslConsecutiveFailures >= SSL_CIRCUIT_THRESHOLD) {
|
||||||
if (sslConsecutiveFailures >= SSL_CIRCUIT_THRESHOLD) {
|
sslCircuitOpenUntil = System.currentTimeMillis() + SSL_CIRCUIT_COOLDOWN_MS;
|
||||||
sslCircuitOpenUntil = System.currentTimeMillis() + SSL_CIRCUIT_COOLDOWN_MS;
|
plugin.getLogger().warning("[Web通信] SSL断路器触发: 连续失败" + sslConsecutiveFailures + "次,暂停轮询60秒");
|
||||||
plugin.getLogger().warning("[Web通信] SSL断路器触发: 连续失败" + sslConsecutiveFailures + "次,暂停轮询60秒");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
plugin.getLogger().warning("[Web通信] POST异常: " + e.getClass().getSimpleName() + ": " + e.getMessage());
|
plugin.getLogger().warning("[Web通信] POST异常: " + e.getClass().getSimpleName() + ": " + e.getMessage());
|
||||||
return null;
|
return null;
|
||||||
@@ -675,6 +673,8 @@ public class WebManager {
|
|||||||
try { Thread.sleep(2000 * attempt); } catch (InterruptedException ie) {}
|
try { Thread.sleep(2000 * attempt); } catch (InterruptedException ie) {}
|
||||||
} else {
|
} else {
|
||||||
plugin.getLogger().warning("[Web通信] POST最终失败: " + e.getMessage());
|
plugin.getLogger().warning("[Web通信] POST最终失败: " + e.getMessage());
|
||||||
|
// ★ SSL断路器:跟踪连续失败(最终失败时计数)
|
||||||
|
sslConsecutiveFailures++;
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -801,24 +801,24 @@ public class WebManager {
|
|||||||
plugin.getLogger().info("[Web通信] 开始首次全量同步(通过DB队列串行化)...");
|
plugin.getLogger().info("[Web通信] 开始首次全量同步(通过DB队列串行化)...");
|
||||||
// 登录相关操作高优先级
|
// 登录相关操作高优先级
|
||||||
submitDbTask("首次-syncUserRegistrations", () -> syncUserRegistrations());
|
submitDbTask("首次-syncUserRegistrations", () -> syncUserRegistrations());
|
||||||
try { Thread.sleep(2000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {}
|
try { Thread.sleep(4000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {}
|
||||||
submitDbTask("首次-pushWebLoginCredentials", () -> pushWebLoginCredentials());
|
submitDbTask("首次-pushWebLoginCredentials", () -> pushWebLoginCredentials());
|
||||||
try { Thread.sleep(2000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {}
|
try { Thread.sleep(4000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {}
|
||||||
// 普通同步操作低优先级(每个任务间随机间隔2-4秒,避免PHP端DB锁)
|
// 普通同步操作低优先级(每个任务间随机间隔2-4秒,避免PHP端DB锁)
|
||||||
submitNormalDbTask("首次-syncOnlinePlayers", () -> syncOnlinePlayers());
|
submitNormalDbTask("首次-syncOnlinePlayers", () -> syncOnlinePlayers());
|
||||||
try { Thread.sleep(2000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {}
|
try { Thread.sleep(4000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {}
|
||||||
submitNormalDbTask("首次-syncShopData", () -> syncShopData());
|
submitNormalDbTask("首次-syncShopData", () -> syncShopData());
|
||||||
try { Thread.sleep(2000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {}
|
try { Thread.sleep(4000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {}
|
||||||
submitNormalDbTask("首次-syncBondBalances", () -> syncBondBalances());
|
submitNormalDbTask("首次-syncBondBalances", () -> syncBondBalances());
|
||||||
try { Thread.sleep(2000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {}
|
try { Thread.sleep(4000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {}
|
||||||
submitNormalDbTask("首次-syncBondTransactions", () -> syncBondTransactions());
|
submitNormalDbTask("首次-syncBondTransactions", () -> syncBondTransactions());
|
||||||
try { Thread.sleep(2000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {}
|
try { Thread.sleep(4000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {}
|
||||||
submitNormalDbTask("首次-syncAllPlayerIps", () -> syncAllPlayerIps());
|
submitNormalDbTask("首次-syncAllPlayerIps", () -> syncAllPlayerIps());
|
||||||
try { Thread.sleep(2000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {}
|
try { Thread.sleep(4000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {}
|
||||||
submitNormalDbTask("首次-syncServiceProviders", () -> syncServiceProviders());
|
submitNormalDbTask("首次-syncServiceProviders", () -> syncServiceProviders());
|
||||||
try { Thread.sleep(2000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {}
|
try { Thread.sleep(4000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {}
|
||||||
submitNormalDbTask("首次-syncLandData", () -> syncLandData());
|
submitNormalDbTask("首次-syncLandData", () -> syncLandData());
|
||||||
try { Thread.sleep(2000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {}
|
try { Thread.sleep(4000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {}
|
||||||
submitNormalDbTask("首次-pollAdminChanges", () -> pollAdminChanges());
|
submitNormalDbTask("首次-pollAdminChanges", () -> pollAdminChanges());
|
||||||
}
|
}
|
||||||
}.runTaskLaterAsynchronously(plugin, 20L * 10);
|
}.runTaskLaterAsynchronously(plugin, 20L * 10);
|
||||||
@@ -1189,19 +1189,19 @@ public class WebManager {
|
|||||||
plugin.getLogger().info("[Web通信] 收到即时同步请求: " + players.toString());
|
plugin.getLogger().info("[Web通信] 收到即时同步请求: " + players.toString());
|
||||||
// 通过DB队列串行化执行(每个任务间错开800ms)
|
// 通过DB队列串行化执行(每个任务间错开800ms)
|
||||||
submitDbTask("即时-syncOnlinePlayers", () -> syncOnlinePlayers());
|
submitDbTask("即时-syncOnlinePlayers", () -> syncOnlinePlayers());
|
||||||
try { Thread.sleep(2000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {}
|
try { Thread.sleep(4000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {}
|
||||||
submitDbTask("即时-pushWebLoginCredentials", () -> pushWebLoginCredentials());
|
submitDbTask("即时-pushWebLoginCredentials", () -> pushWebLoginCredentials());
|
||||||
try { Thread.sleep(2000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {}
|
try { Thread.sleep(4000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {}
|
||||||
submitDbTask("即时-syncUserRegistrations", () -> syncUserRegistrations());
|
submitDbTask("即时-syncUserRegistrations", () -> syncUserRegistrations());
|
||||||
try { Thread.sleep(2000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {}
|
try { Thread.sleep(4000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {}
|
||||||
submitNormalDbTask("即时-pullPendingTransactions", () -> pullPendingTransactions());
|
submitNormalDbTask("即时-pullPendingTransactions", () -> pullPendingTransactions());
|
||||||
try { Thread.sleep(2000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {}
|
try { Thread.sleep(4000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {}
|
||||||
submitNormalDbTask("即时-pullShopStock", () -> pullShopStock());
|
submitNormalDbTask("即时-pullShopStock", () -> pullShopStock());
|
||||||
try { Thread.sleep(2000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {}
|
try { Thread.sleep(4000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {}
|
||||||
submitNormalDbTask("即时-pullBondChanges", () -> pullBondChanges());
|
submitNormalDbTask("即时-pullBondChanges", () -> pullBondChanges());
|
||||||
try { Thread.sleep(2000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {}
|
try { Thread.sleep(4000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {}
|
||||||
submitNormalDbTask("即时-syncAllPlayerIps", () -> syncAllPlayerIps());
|
submitNormalDbTask("即时-syncAllPlayerIps", () -> syncAllPlayerIps());
|
||||||
try { Thread.sleep(2000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {}
|
try { Thread.sleep(4000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {}
|
||||||
submitNormalDbTask("即时-syncServiceProviders", () -> syncServiceProviders());
|
submitNormalDbTask("即时-syncServiceProviders", () -> syncServiceProviders());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1224,17 +1224,17 @@ public class WebManager {
|
|||||||
lastOnlineCheckTime = System.currentTimeMillis();
|
lastOnlineCheckTime = System.currentTimeMillis();
|
||||||
// 通过DB队列串行化执行最后一轮同步(每个任务间随机间隔2-4秒,避免与定时轮询冲突)
|
// 通过DB队列串行化执行最后一轮同步(每个任务间随机间隔2-4秒,避免与定时轮询冲突)
|
||||||
submitDbTask("末轮-syncOnlinePlayers", () -> syncOnlinePlayers());
|
submitDbTask("末轮-syncOnlinePlayers", () -> syncOnlinePlayers());
|
||||||
try { Thread.sleep(2000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {}
|
try { Thread.sleep(4000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {}
|
||||||
submitDbTask("末轮-pushWebLoginCredentials", () -> pushWebLoginCredentials());
|
submitDbTask("末轮-pushWebLoginCredentials", () -> pushWebLoginCredentials());
|
||||||
try { Thread.sleep(2000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {}
|
try { Thread.sleep(4000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {}
|
||||||
submitDbTask("末轮-syncUserRegistrations", () -> syncUserRegistrations());
|
submitDbTask("末轮-syncUserRegistrations", () -> syncUserRegistrations());
|
||||||
try { Thread.sleep(2000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {}
|
try { Thread.sleep(4000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {}
|
||||||
submitDbTask("末轮-syncBondTransactions", () -> syncBondTransactions());
|
submitDbTask("末轮-syncBondTransactions", () -> syncBondTransactions());
|
||||||
try { Thread.sleep(2000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {}
|
try { Thread.sleep(4000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {}
|
||||||
submitNormalDbTask("末轮-pullPendingTransactions", () -> pullPendingTransactions());
|
submitNormalDbTask("末轮-pullPendingTransactions", () -> pullPendingTransactions());
|
||||||
try { Thread.sleep(2000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {}
|
try { Thread.sleep(4000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {}
|
||||||
submitNormalDbTask("末轮-pullShopStock", () -> pullShopStock());
|
submitNormalDbTask("末轮-pullShopStock", () -> pullShopStock());
|
||||||
try { Thread.sleep(2000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {}
|
try { Thread.sleep(4000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {}
|
||||||
submitNormalDbTask("末轮-pullBondChanges", () -> pullBondChanges());
|
submitNormalDbTask("末轮-pullBondChanges", () -> pullBondChanges());
|
||||||
plugin.getLogger().info("[Web通信] 检测到全员下线超60秒,执行最后一轮同步(通过DB队列),调度器继续运行(玩家上线自动恢复)");
|
plugin.getLogger().info("[Web通信] 检测到全员下线超60秒,执行最后一轮同步(通过DB队列),调度器继续运行(玩家上线自动恢复)");
|
||||||
plugin.getLogger().warning("\n" +
|
plugin.getLogger().warning("\n" +
|
||||||
@@ -1285,28 +1285,28 @@ public class WebManager {
|
|||||||
|
|
||||||
// 登录/注册相关(始终执行,随机间隔2-4秒避免PHP端DB锁)
|
// 登录/注册相关(始终执行,随机间隔2-4秒避免PHP端DB锁)
|
||||||
submitDbTask("周期-pushWebLoginCredentials", () -> pushWebLoginCredentials());
|
submitDbTask("周期-pushWebLoginCredentials", () -> pushWebLoginCredentials());
|
||||||
try { Thread.sleep(2000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {}
|
try { Thread.sleep(4000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {}
|
||||||
submitDbTask("周期-syncUserRegistrations", () -> syncUserRegistrations());
|
submitDbTask("周期-syncUserRegistrations", () -> syncUserRegistrations());
|
||||||
try { Thread.sleep(2000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {}
|
try { Thread.sleep(4000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {}
|
||||||
|
|
||||||
if (online) {
|
if (online) {
|
||||||
// 在线:执行全量同步(每个任务随机间隔2-4秒)
|
// 在线:执行全量同步(每个任务随机间隔2-4秒)
|
||||||
submitDbTask("周期-syncOnlinePlayers", () -> syncOnlinePlayers());
|
submitDbTask("周期-syncOnlinePlayers", () -> syncOnlinePlayers());
|
||||||
try { Thread.sleep(2000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {}
|
try { Thread.sleep(4000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {}
|
||||||
submitDbTask("周期-syncBondTransactions", () -> syncBondTransactions());
|
submitDbTask("周期-syncBondTransactions", () -> syncBondTransactions());
|
||||||
try { Thread.sleep(2000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {}
|
try { Thread.sleep(4000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {}
|
||||||
submitNormalDbTask("周期-pullPendingTransactions", () -> pullPendingTransactions());
|
submitNormalDbTask("周期-pullPendingTransactions", () -> pullPendingTransactions());
|
||||||
try { Thread.sleep(2000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {}
|
try { Thread.sleep(4000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {}
|
||||||
submitNormalDbTask("周期-pullShopStock", () -> pullShopStock());
|
submitNormalDbTask("周期-pullShopStock", () -> pullShopStock());
|
||||||
try { Thread.sleep(2000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {}
|
try { Thread.sleep(4000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {}
|
||||||
submitNormalDbTask("周期-pullBondChanges", () -> pullBondChanges());
|
submitNormalDbTask("周期-pullBondChanges", () -> pullBondChanges());
|
||||||
try { Thread.sleep(2000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {}
|
try { Thread.sleep(4000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {}
|
||||||
submitNormalDbTask("周期-syncAllPlayerIps", () -> syncAllPlayerIps());
|
submitNormalDbTask("周期-syncAllPlayerIps", () -> syncAllPlayerIps());
|
||||||
try { Thread.sleep(2000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {}
|
try { Thread.sleep(4000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {}
|
||||||
submitNormalDbTask("周期-syncServiceProviders", () -> syncServiceProviders());
|
submitNormalDbTask("周期-syncServiceProviders", () -> syncServiceProviders());
|
||||||
try { Thread.sleep(2000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {}
|
try { Thread.sleep(4000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {}
|
||||||
submitNormalDbTask("周期-syncLandData", () -> syncLandData());
|
submitNormalDbTask("周期-syncLandData", () -> syncLandData());
|
||||||
try { Thread.sleep(2000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {}
|
try { Thread.sleep(4000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {}
|
||||||
submitNormalDbTask("周期-pollAdminChanges", () -> pollAdminChanges());
|
submitNormalDbTask("周期-pollAdminChanges", () -> pollAdminChanges());
|
||||||
} else {
|
} else {
|
||||||
// ★ 不在线:跳过非必要同步任务
|
// ★ 不在线:跳过非必要同步任务
|
||||||
|
|||||||
Reference in New Issue
Block a user