Skip to content

server : fix coredump on std::terminate() #12831 #13088

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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions examples/server/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1763,12 +1763,16 @@ struct server_response {
std::unique_lock<std::mutex> lock(mutex_results);
condition_results.wait(lock, [&]{
if (!running) {
SRV_DBG("%s : queue result stop\n", __func__);
std::terminate(); // we cannot return here since the caller is HTTP code
return true;
}
return !queue_results.empty();
});

if (!running) {
SRV_DBG("%s : queue result stop\n", __func__);
auto res = std::make_unique<server_task_result_error>();
Copy link
Collaborator

@ngxson ngxson Apr 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not a good idea to return server_task_result_error

Some handlers create task with type cancel upon receiving server_task_result_error, so the server will probably hangs. You should check all code paths, not just one single use case.

It's better to throw an exception here

res->err_msg = "server stopped";
return res;
}
for (size_t i = 0; i < queue_results.size(); i++) {
if (id_tasks.find(queue_results[i]->id) != id_tasks.end()) {
server_task_result_ptr res = std::move(queue_results[i]);
Expand Down Expand Up @@ -1798,7 +1802,9 @@ struct server_response {
std::cv_status cr_res = condition_results.wait_for(lock, std::chrono::seconds(timeout));
if (!running) {
SRV_DBG("%s : queue result stop\n", __func__);
std::terminate(); // we cannot return here since the caller is HTTP code
auto res = std::make_unique<server_task_result_error>();
res->err_msg = "server stopped";
return res;
}
if (cr_res == std::cv_status::timeout) {
return nullptr;
Expand Down