Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.

Commit 84ae2aa

Browse files
committed
fix: thread hang if unload model when still receiving stream data
1 parent 9b8dac0 commit 84ae2aa

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

controllers/llamaCPP.cc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,7 @@ void llamaCPP::InferenceImpl(
190190
if (llama.model_type == ModelType::EMBEDDING) {
191191
LOG_WARN << "Not support completion for embedding model";
192192
Json::Value jsonResp;
193-
jsonResp["message"] =
194-
"Not support completion for embedding model";
193+
jsonResp["message"] = "Not support completion for embedding model";
195194
auto resp = nitro_utils::nitroHttpJsonResponse(jsonResp);
196195
resp->setStatusCode(drogon::k400BadRequest);
197196
callback(resp);
@@ -420,7 +419,8 @@ void llamaCPP::InferenceImpl(
420419

421420
// Since this is an async task, we will wait for the task to be
422421
// completed
423-
while (state->inference_status != FINISHED && retries < 10) {
422+
while (state->inference_status != FINISHED && retries < 10 &&
423+
state->instance->llama.model_loaded_external) {
424424
// Should wait chunked_content_provider lambda to be called within
425425
// 3s
426426
if (state->inference_status == PENDING) {
@@ -740,9 +740,10 @@ void llamaCPP::StopBackgroundTask() {
740740
if (llama.model_loaded_external) {
741741
llama.model_loaded_external = false;
742742
llama.condition_tasks.notify_one();
743-
LOG_INFO << "Background task stopped! ";
743+
LOG_INFO << "Stopping background task! ";
744744
if (backgroundThread.joinable()) {
745745
backgroundThread.join();
746746
}
747+
LOG_INFO << "Background task stopped! ";
747748
}
748749
}

0 commit comments

Comments
 (0)