-
-
Notifications
You must be signed in to change notification settings - Fork 123
fix(nvhttp): 修复恢复时app_id不同导致运行应用意外退出 #628
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -62,6 +62,21 @@ namespace proc { | |
| } | ||
| }; | ||
|
|
||
| namespace { | ||
| ctx_t | ||
| make_desktop_app() { | ||
| ctx_t app; | ||
| app.name = std::string(DESKTOP_APP_NAME); | ||
| app.image_path = std::string(DESKTOP_APP_IMAGE_PATH); | ||
| app.id = std::to_string(DESKTOP_APP_ID); | ||
| app.auto_detach = true; | ||
| app.wait_all = true; | ||
| app.mouse_mode = 0; | ||
| app.exit_timeout = std::chrono::seconds { 5 }; | ||
| return app; | ||
|
Comment on lines
+65
to
+76
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 把 这里的 🛠️ 建议修改- ctx_t app;
+ ctx_t app {};
app.name = std::string(DESKTOP_APP_NAME);
app.image_path = std::string(DESKTOP_APP_IMAGE_PATH);
app.id = std::to_string(DESKTOP_APP_ID);
app.auto_detach = true;
app.wait_all = true;
app.mouse_mode = 0;
app.exit_timeout = std::chrono::seconds { 5 };
return app;As per coding guidelines,"Sunshine 核心 C++ 源码,自托管游戏串流服务器。审查要点:内存安全、 线程安全、RAII 资源管理、安全漏洞。注意预处理宏控制的平台相关代码。" 🧰 Tools🪛 Cppcheck (2.20.0)[error] 76-76: Uninitialized variable (uninitvar) 🤖 Prompt for AI Agents |
||
| } | ||
| } // namespace | ||
|
|
||
| std::unique_ptr<platf::deinit_t> | ||
| init() { | ||
| return std::make_unique<deinit_t>(); | ||
|
|
@@ -156,17 +171,23 @@ namespace proc { | |
| // Ensure starting from a clean slate | ||
| terminate(); | ||
|
|
||
| auto iter = std::find_if(_apps.begin(), _apps.end(), [&app_id](const auto app) { | ||
| return app.id == std::to_string(app_id); | ||
| }); | ||
| _app_id = app_id; | ||
| if (app_id == DESKTOP_APP_ID) { | ||
| _app = make_desktop_app(); | ||
| } | ||
| else { | ||
| auto iter = std::find_if(_apps.begin(), _apps.end(), [&app_id](const auto app) { | ||
| return app.id == std::to_string(app_id); | ||
| }); | ||
|
|
||
| if (iter == _apps.end()) { | ||
| BOOST_LOG(error) << "Couldn't find app with ID ["sv << app_id << ']'; | ||
| return 404; | ||
| if (iter == _apps.end()) { | ||
| BOOST_LOG(error) << "Couldn't find app with ID ["sv << app_id << ']'; | ||
| return 404; | ||
| } | ||
|
|
||
| _app = *iter; | ||
| } | ||
|
|
||
| _app_id = app_id; | ||
| _app = *iter; | ||
| _app_prep_begin = std::begin(_app.prep_cmds); | ||
| _app_prep_it = _app_prep_begin; | ||
|
|
||
|
|
@@ -409,7 +430,8 @@ namespace proc { | |
| for (const auto &app : apps) { | ||
| combined_info += app.id + app.name; | ||
| } | ||
|
|
||
| combined_info += std::to_string(DESKTOP_APP_ID) + std::string(DESKTOP_APP_NAME); | ||
|
|
||
| // Use CRC32 for the tag, same as used elsewhere | ||
| auto crc = calculate_crc32(combined_info); | ||
| _apps_etag = std::to_string(crc); | ||
|
|
@@ -441,6 +463,10 @@ namespace proc { | |
| // Returns http content-type header compatible image type. | ||
| std::string | ||
| proc_t::get_app_image(int app_id) { | ||
| if (app_id == DESKTOP_APP_ID) { | ||
| return validate_app_image_path(std::string(DESKTOP_APP_IMAGE_PATH)); | ||
| } | ||
|
|
||
| auto iter = std::find_if(_apps.begin(), _apps.end(), [&app_id](const auto app) { | ||
| return app.id == std::to_string(app_id); | ||
| }); | ||
|
|
@@ -451,6 +477,10 @@ namespace proc { | |
|
|
||
| std::string | ||
| proc_t::get_app_name(int app_id) { | ||
| if (app_id == DESKTOP_APP_ID) { | ||
| return std::string(DESKTOP_APP_NAME); | ||
| } | ||
|
|
||
| auto iter = std::find_if(_apps.begin(), _apps.end(), [&app_id](const auto app) { | ||
| return app.id == std::to_string(app_id); | ||
| }); | ||
|
|
@@ -459,6 +489,10 @@ namespace proc { | |
|
|
||
| std::string | ||
| proc_t::get_app_cmd(int app_id) { | ||
| if (app_id == DESKTOP_APP_ID) { | ||
| return std::string(); | ||
| } | ||
|
|
||
| auto iter = std::find_if(_apps.begin(), _apps.end(), [&app_id](const auto app) { | ||
| return app.id == std::to_string(app_id); | ||
| }); | ||
|
|
@@ -885,15 +919,19 @@ namespace proc { | |
| ctx.mouse_mode = mouse_mode.value_or(0); | ||
| ctx.exit_timeout = std::chrono::seconds { exit_timeout.value_or(5) }; | ||
|
|
||
| auto possible_ids = calculate_app_id(name, ctx.image_path, i++); | ||
| if (ids.count(std::get<0>(possible_ids)) == 0) { | ||
| // Avoid using index to generate id if possible | ||
| ctx.id = std::get<0>(possible_ids); | ||
| } | ||
| else { | ||
| // Fallback to include index on collision | ||
| ctx.id = std::get<1>(possible_ids); | ||
| } | ||
| std::tuple<std::string, std::string> possible_ids; | ||
| do { | ||
| possible_ids = calculate_app_id(name, ctx.image_path, i++); | ||
| if (ids.count(std::get<0>(possible_ids)) == 0) { | ||
| // Avoid using index to generate id if possible | ||
| ctx.id = std::get<0>(possible_ids); | ||
| } | ||
| else { | ||
| // Fallback to include index on collision | ||
| ctx.id = std::get<1>(possible_ids); | ||
| } | ||
| } while (ids.count(ctx.id) != 0 || ctx.id == std::to_string(DESKTOP_APP_ID)); | ||
|
Comment on lines
+922
to
+933
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 保留 ID 命中时,这个重试循环会卡死。 如果 🛠️ 建议修改- std::tuple<std::string, std::string> possible_ids;
+ const auto reserved_id = std::to_string(DESKTOP_APP_ID);
+ std::tuple<std::string, std::string> possible_ids;
do {
possible_ids = calculate_app_id(name, ctx.image_path, i++);
- if (ids.count(std::get<0>(possible_ids)) == 0) {
+ if (std::get<0>(possible_ids) != reserved_id &&
+ ids.count(std::get<0>(possible_ids)) == 0) {
// Avoid using index to generate id if possible
ctx.id = std::get<0>(possible_ids);
}
else {
// Fallback to include index on collision
ctx.id = std::get<1>(possible_ids);
}
- } while (ids.count(ctx.id) != 0 || ctx.id == std::to_string(DESKTOP_APP_ID));
+ } while (ids.count(ctx.id) != 0 || ctx.id == reserved_id);🤖 Prompt for AI Agents |
||
|
|
||
| ids.insert(ctx.id); | ||
|
|
||
| ctx.name = std::move(name); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
内部执行失败不要直接回填为负的
status_code。proc::proc.execute()这里除了404还会返回-1。直接写进 XML 会产生无效状态码,客户端侧的失败分支会变得不可预测。更稳妥的做法是只透传明确的协议状态(比如404),其余内部错误统一映射到500/503,原始返回值继续只打日志。🛠️ 建议修改
📝 Committable suggestion
🤖 Prompt for AI Agents