SteamWar/SpigotCore
Archiviert
13
0

New 1.18 crash detector
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Dieser Commit ist enthalten in:
Lixfel 2022-05-13 20:47:02 +02:00
Ursprung a968a9f927
Commit 7639a6ad46
2 geänderte Dateien mit 69 neuen und 0 gelöschten Zeilen

Datei anzeigen

@ -84,6 +84,7 @@ public class Core extends JavaPlugin{
} }
private ErrorHandler errorHandler; private ErrorHandler errorHandler;
private CrashDetector crashDetector;
@Override @Override
public void onLoad() { public void onLoad() {
@ -94,6 +95,8 @@ public class Core extends JavaPlugin{
public void onEnable() { public void onEnable() {
setSqlConfig(); setSqlConfig();
errorHandler = new ErrorHandler(); errorHandler = new ErrorHandler();
if(VERSION > 15)
crashDetector = new CrashDetector();
Bukkit.getPluginManager().registerEvents(new PlayerJoinedEvent(), this); Bukkit.getPluginManager().registerEvents(new PlayerJoinedEvent(), this);
Bukkit.getPluginManager().registerEvents(new ChattingEvent(), this); Bukkit.getPluginManager().registerEvents(new ChattingEvent(), this);
@ -112,6 +115,8 @@ public class Core extends JavaPlugin{
@Override @Override
public void onDisable() { public void onDisable() {
TinyProtocol.instance.close(); TinyProtocol.instance.close();
if(VERSION > 15)
crashDetector.stop();
errorHandler.unregister(); errorHandler.unregister();
if(!standalone) { if(!standalone) {
Statement.close(); Statement.close();

Datei anzeigen

@ -0,0 +1,64 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2022 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.core;
import de.steamwar.sql.SWException;
import org.bukkit.Bukkit;
import java.util.Arrays;
import java.util.concurrent.atomic.AtomicLong;
import java.util.stream.Collectors;
public class CrashDetector {
private static final long TIMEOUT = 20000;
private final AtomicLong lastTick = new AtomicLong(Long.MAX_VALUE);
private final Thread mainThread = Thread.currentThread();
private final Thread watchdog;
private boolean run = true;
public CrashDetector () {
Bukkit.getScheduler().runTaskTimer(Core.getInstance(), () -> lastTick.set(System.currentTimeMillis()), 0, 1);
watchdog = new Thread(this::run, "SteamWar Watchdog");
watchdog.setDaemon(true);
watchdog.start();
}
public void stop() {
run = false;
watchdog.interrupt();
}
private void run() {
while (run) {
long curTime = System.currentTimeMillis();
if(curTime + TIMEOUT > lastTick.get()) {
SWException.log(Bukkit.getServer().getVersion() + " server hung for " + (curTime - lastTick.get()) + "ms, ", Arrays.stream(mainThread.getStackTrace()).map(StackTraceElement::toString).collect(Collectors.joining("\n")));
lastTick.set(curTime);
}
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
}
}