mirror of
https://github.com/MatsuriDayo/nekoray.git
synced 2025-12-17 20:44:38 +03:00
fix: core crashed
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
#include <QTimer>
|
||||
#include <QDir>
|
||||
#include <QApplication>
|
||||
#include <QThread>
|
||||
#include <QElapsedTimer>
|
||||
|
||||
namespace NekoRay::sys {
|
||||
|
||||
@@ -74,6 +74,10 @@ namespace NekoRay::sys {
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
QElapsedTimer coreRestartTimer;
|
||||
|
||||
CoreProcess::CoreProcess(const QString &core_path, const QStringList &args) : ExternalProcess() {
|
||||
ExternalProcess::managed = false;
|
||||
ExternalProcess::program = core_path;
|
||||
@@ -106,18 +110,24 @@ namespace NekoRay::sys {
|
||||
if (!dataStore->prepare_exit && state == QProcess::NotRunning) {
|
||||
if (failed_to_start) return; // no retry
|
||||
|
||||
restart_id = NekoRay::dataStore->started_id;
|
||||
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
|
||||
setTimeout(
|
||||
[=] {
|
||||
Kill();
|
||||
ExternalProcess::started = false;
|
||||
Start();
|
||||
},
|
||||
this, 1000);
|
||||
restart_id = NekoRay::dataStore->started_id;
|
||||
MW_show_log("[Error] " + QObject::tr("Core exited, restarting."));
|
||||
|
||||
setTimeout([=] { Restart(); }, this, 1000);
|
||||
} else if (state == QProcess::Running && restart_id >= 0) {
|
||||
// Restart profile
|
||||
setTimeout(
|
||||
@@ -145,4 +155,10 @@ namespace NekoRay::sys {
|
||||
write((dataStore->core_token + "\n").toUtf8());
|
||||
}
|
||||
|
||||
void CoreProcess::Restart() {
|
||||
Kill();
|
||||
ExternalProcess::started = false;
|
||||
Start();
|
||||
}
|
||||
|
||||
} // namespace NekoRay::sys
|
||||
|
||||
@@ -33,6 +33,8 @@ namespace NekoRay::sys {
|
||||
|
||||
void Start() override;
|
||||
|
||||
void Restart();
|
||||
|
||||
private:
|
||||
bool show_stderr = false;
|
||||
bool failed_to_start = false;
|
||||
|
||||
@@ -1462,10 +1462,6 @@ End: %2</source>
|
||||
<source>Failed to stop, please restart the program.</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Core exits too frequently, stop automatic restart this profile.</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>ProxyItem</name>
|
||||
@@ -1602,6 +1598,10 @@ Direct: %2</source>
|
||||
<source>Core exited, restarting.</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Core exits too frequently, stop automatic restart this profile.</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>Qv2ray::ui::widgets::AutoCompleteTextEdit</name>
|
||||
|
||||
@@ -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>
|
||||
<translation>如果长时间没有反应,建议重启软件。</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Core exits too frequently, stop automatic restart this profile.</source>
|
||||
<translation>Core 退出太频繁,停止自动重启。</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>ProxyItem</name>
|
||||
@@ -1608,6 +1604,10 @@ Release note:
|
||||
<source>Core exited, restarting.</source>
|
||||
<translation>Core 退出,正在重新启动。</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Core exits too frequently, stop automatic restart this profile.</source>
|
||||
<translation>Core 退出太频繁,停止自动重启。</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>Qv2ray::ui::widgets::AutoCompleteTextEdit</name>
|
||||
|
||||
@@ -44,9 +44,6 @@
|
||||
#include <QMessageBox>
|
||||
#include <QDir>
|
||||
#include <QFileInfo>
|
||||
#include <QElapsedTimer>
|
||||
|
||||
QElapsedTimer coreRestartTimer;
|
||||
|
||||
void UI_InitMainWindow() {
|
||||
mainwindow = new MainWindow;
|
||||
@@ -579,15 +576,6 @@ void MainWindow::dialog_message_impl(const QString &sender, const QString &info)
|
||||
} else if (info == "CoreCrashed") {
|
||||
neko_stop(true);
|
||||
} 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());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -230,6 +230,15 @@ void MainWindow::neko_start(int _id) {
|
||||
}
|
||||
|
||||
auto neko_start_stage2 = [=] {
|
||||
if (!NekoRay::dataStore->core_running) {
|
||||
runOnUiThread(
|
||||
[=] {
|
||||
core_process->Restart();
|
||||
},
|
||||
DS_cores);
|
||||
QThread::sleep(1);
|
||||
}
|
||||
|
||||
#ifndef NKR_NO_GRPC
|
||||
libcore::LoadConfigReq req;
|
||||
req.set_core_config(QJsonObject2QString(result->coreConfig, true).toStdString());
|
||||
@@ -244,6 +253,8 @@ void MainWindow::neko_start(int _id) {
|
||||
if (rpcOK && !error.isEmpty()) {
|
||||
runOnUiThread([=] { MessageBoxWarning("LoadConfig return error", error); });
|
||||
return false;
|
||||
} else if (!rpcOK) {
|
||||
return false;
|
||||
}
|
||||
//
|
||||
NekoRay::traffic::trafficLooper->proxy = result->outboundStat.get();
|
||||
@@ -338,6 +349,8 @@ void MainWindow::neko_stop(bool crash, bool sem) {
|
||||
if (rpcOK && !error.isEmpty()) {
|
||||
runOnUiThread([=] { MessageBoxWarning("Stop return error", error); });
|
||||
return false;
|
||||
} else if (!rpcOK) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user