fix: core crashed

This commit is contained in:
arm64v8a
2023-05-19 18:30:43 +09:00
parent ec25e0ed00
commit fc9d853bae
6 changed files with 49 additions and 30 deletions

View File

@@ -4,7 +4,7 @@
#include <QTimer> #include <QTimer>
#include <QDir> #include <QDir>
#include <QApplication> #include <QApplication>
#include <QThread> #include <QElapsedTimer>
namespace NekoRay::sys { namespace NekoRay::sys {
@@ -74,6 +74,10 @@ namespace NekoRay::sys {
} }
} }
//
QElapsedTimer coreRestartTimer;
CoreProcess::CoreProcess(const QString &core_path, const QStringList &args) : ExternalProcess() { CoreProcess::CoreProcess(const QString &core_path, const QStringList &args) : ExternalProcess() {
ExternalProcess::managed = false; ExternalProcess::managed = false;
ExternalProcess::program = core_path; ExternalProcess::program = core_path;
@@ -106,18 +110,24 @@ namespace NekoRay::sys {
if (!dataStore->prepare_exit && state == QProcess::NotRunning) { if (!dataStore->prepare_exit && state == QProcess::NotRunning) {
if (failed_to_start) return; // no retry if (failed_to_start) return; // no retry
restart_id = NekoRay::dataStore->started_id;
MW_dialog_message("ExternalProcess", "CoreCrashed"); MW_dialog_message("ExternalProcess", "CoreCrashed");
MW_show_log("[Error] " + QObject::tr("Core exited, restarting."));
// Retry rate limit
if (coreRestartTimer.isValid()) {
if (coreRestartTimer.restart() < 10 * 1000) {
coreRestartTimer = QElapsedTimer();
MW_show_log("[Error] " + QObject::tr("Core exits too frequently, stop automatic restart this profile."));
return;
}
} else {
coreRestartTimer.start();
}
// Restart // Restart
setTimeout( restart_id = NekoRay::dataStore->started_id;
[=] { MW_show_log("[Error] " + QObject::tr("Core exited, restarting."));
Kill();
ExternalProcess::started = false; setTimeout([=] { Restart(); }, this, 1000);
Start();
},
this, 1000);
} else if (state == QProcess::Running && restart_id >= 0) { } else if (state == QProcess::Running && restart_id >= 0) {
// Restart profile // Restart profile
setTimeout( setTimeout(
@@ -145,4 +155,10 @@ namespace NekoRay::sys {
write((dataStore->core_token + "\n").toUtf8()); write((dataStore->core_token + "\n").toUtf8());
} }
void CoreProcess::Restart() {
Kill();
ExternalProcess::started = false;
Start();
}
} // namespace NekoRay::sys } // namespace NekoRay::sys

View File

@@ -33,6 +33,8 @@ namespace NekoRay::sys {
void Start() override; void Start() override;
void Restart();
private: private:
bool show_stderr = false; bool show_stderr = false;
bool failed_to_start = false; bool failed_to_start = false;

View File

@@ -1462,10 +1462,6 @@ End: %2</source>
<source>Failed to stop, please restart the program.</source> <source>Failed to stop, please restart the program.</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Core exits too frequently, stop automatic restart this profile.</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>ProxyItem</name> <name>ProxyItem</name>
@@ -1602,6 +1598,10 @@ Direct: %2</source>
<source>Core exited, restarting.</source> <source>Core exited, restarting.</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Core exits too frequently, stop automatic restart this profile.</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>Qv2ray::ui::widgets::AutoCompleteTextEdit</name> <name>Qv2ray::ui::widgets::AutoCompleteTextEdit</name>

View File

@@ -1469,10 +1469,6 @@ Split by line.</source>
<source>If there is no response for a long time, it is recommended to restart the software.</source> <source>If there is no response for a long time, it is recommended to restart the software.</source>
<translation></translation> <translation></translation>
</message> </message>
<message>
<source>Core exits too frequently, stop automatic restart this profile.</source>
<translation>Core 退</translation>
</message>
</context> </context>
<context> <context>
<name>ProxyItem</name> <name>ProxyItem</name>
@@ -1608,6 +1604,10 @@ Release note:
<source>Core exited, restarting.</source> <source>Core exited, restarting.</source>
<translation>Core 退</translation> <translation>Core 退</translation>
</message> </message>
<message>
<source>Core exits too frequently, stop automatic restart this profile.</source>
<translation>Core 退</translation>
</message>
</context> </context>
<context> <context>
<name>Qv2ray::ui::widgets::AutoCompleteTextEdit</name> <name>Qv2ray::ui::widgets::AutoCompleteTextEdit</name>

View File

@@ -44,9 +44,6 @@
#include <QMessageBox> #include <QMessageBox>
#include <QDir> #include <QDir>
#include <QFileInfo> #include <QFileInfo>
#include <QElapsedTimer>
QElapsedTimer coreRestartTimer;
void UI_InitMainWindow() { void UI_InitMainWindow() {
mainwindow = new MainWindow; mainwindow = new MainWindow;
@@ -579,15 +576,6 @@ void MainWindow::dialog_message_impl(const QString &sender, const QString &info)
} else if (info == "CoreCrashed") { } else if (info == "CoreCrashed") {
neko_stop(true); neko_stop(true);
} else if (info.startsWith("CoreRestarted")) { } else if (info.startsWith("CoreRestarted")) {
if (coreRestartTimer.isValid()) {
if (coreRestartTimer.restart() < 10 * 1000) {
coreRestartTimer = QElapsedTimer();
show_log_impl("[Error] " + tr("Core exits too frequently, stop automatic restart this profile."));
return;
}
} else {
coreRestartTimer.start();
}
neko_start(info.split(",")[1].toInt()); neko_start(info.split(",")[1].toInt());
} }
} }

View File

@@ -230,6 +230,15 @@ void MainWindow::neko_start(int _id) {
} }
auto neko_start_stage2 = [=] { auto neko_start_stage2 = [=] {
if (!NekoRay::dataStore->core_running) {
runOnUiThread(
[=] {
core_process->Restart();
},
DS_cores);
QThread::sleep(1);
}
#ifndef NKR_NO_GRPC #ifndef NKR_NO_GRPC
libcore::LoadConfigReq req; libcore::LoadConfigReq req;
req.set_core_config(QJsonObject2QString(result->coreConfig, true).toStdString()); req.set_core_config(QJsonObject2QString(result->coreConfig, true).toStdString());
@@ -244,6 +253,8 @@ void MainWindow::neko_start(int _id) {
if (rpcOK && !error.isEmpty()) { if (rpcOK && !error.isEmpty()) {
runOnUiThread([=] { MessageBoxWarning("LoadConfig return error", error); }); runOnUiThread([=] { MessageBoxWarning("LoadConfig return error", error); });
return false; return false;
} else if (!rpcOK) {
return false;
} }
// //
NekoRay::traffic::trafficLooper->proxy = result->outboundStat.get(); NekoRay::traffic::trafficLooper->proxy = result->outboundStat.get();
@@ -338,6 +349,8 @@ void MainWindow::neko_stop(bool crash, bool sem) {
if (rpcOK && !error.isEmpty()) { if (rpcOK && !error.isEmpty()) {
runOnUiThread([=] { MessageBoxWarning("Stop return error", error); }); runOnUiThread([=] { MessageBoxWarning("Stop return error", error); });
return false; return false;
} else if (!rpcOK) {
return false;
} }
} }
#endif #endif