From f0f7647f4c254a2caac3431e93c56ae2038688ee Mon Sep 17 00:00:00 2001 From: dengyingxu Date: Mon, 10 Nov 2025 22:33:54 +0800 Subject: [PATCH] bugfix: eliminate use-after-move undefined behavior. --- xllm/api_service/chat_service_impl.cpp | 17 ++++++++++++----- xllm/api_service/completion_service_impl.cpp | 6 ++++-- xllm/api_service/embedding_service_impl.cpp | 3 ++- .../image_generation_service_impl.cpp | 3 ++- 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/xllm/api_service/chat_service_impl.cpp b/xllm/api_service/chat_service_impl.cpp index 7ff09d5a4..e58426a94 100644 --- a/xllm/api_service/chat_service_impl.cpp +++ b/xllm/api_service/chat_service_impl.cpp @@ -625,6 +625,10 @@ void ChatServiceImpl::process_async_impl(std::shared_ptr call) { CHECK(stream_parser != nullptr) << "create StreamOutputParser failed!"; } + auto saved_tools = request_params.tools; + auto saved_streaming = request_params.streaming; + auto saved_request_id = request_params.request_id; + master_->handle_request( std::move(messages), std::move(prompt_tokens), @@ -633,12 +637,12 @@ void ChatServiceImpl::process_async_impl(std::shared_ptr call) { [call, model, master = master_, - stream = request_params.streaming, + stream = std::move(saved_streaming), include_usage = include_usage, first_message_sent = std::unordered_set(), - request_id = request_params.request_id, + request_id = std::move(saved_request_id), created_time = absl::ToUnixSeconds(absl::Now()), - json_tools = request_params.tools, + json_tools = std::move(saved_tools), tool_call_parser_format = tool_call_parser_format_, reasoning_parser_format = reasoning_parser_format_, is_force_reasoning = is_force_reasoning_, @@ -741,6 +745,9 @@ void MMChatServiceImpl::process_async_impl(std::shared_ptr call) { include_usage = rpc_request.stream_options().include_usage(); } + auto saved_streaming = request_params.streaming; + auto saved_request_id = request_params.request_id; + // schedule the request master_->handle_request( std::move(messages), @@ -749,10 +756,10 @@ void MMChatServiceImpl::process_async_impl(std::shared_ptr call) { [call, model, master = master_, - stream = request_params.streaming, + stream = std::move(saved_streaming), include_usage = include_usage, first_message_sent = std::unordered_set(), - request_id = request_params.request_id, + request_id = std::move(saved_request_id), created_time = absl::ToUnixSeconds(absl::Now())]( const RequestOutput& req_output) mutable -> bool { if (req_output.status.has_value()) { diff --git a/xllm/api_service/completion_service_impl.cpp b/xllm/api_service/completion_service_impl.cpp index d364074b8..c7dd4a667 100644 --- a/xllm/api_service/completion_service_impl.cpp +++ b/xllm/api_service/completion_service_impl.cpp @@ -196,6 +196,8 @@ void CompletionServiceImpl::process_async_impl( request_params.decode_address = rpc_request.routing().decode_name(); } + auto saved_streaming = request_params.streaming; + auto saved_request_id = request_params.request_id; // schedule the request master_->handle_request( std::move(rpc_request.prompt()), @@ -205,9 +207,9 @@ void CompletionServiceImpl::process_async_impl( [call, model, master = master_, - stream = request_params.streaming, + stream = std::move(saved_streaming), include_usage = include_usage, - request_id = request_params.request_id, + request_id = std::move(saved_request_id), created_time = absl::ToUnixSeconds(absl::Now())]( const RequestOutput& req_output) -> bool { if (req_output.status.has_value()) { diff --git a/xllm/api_service/embedding_service_impl.cpp b/xllm/api_service/embedding_service_impl.cpp index 8870c5074..a3d16ee2d 100644 --- a/xllm/api_service/embedding_service_impl.cpp +++ b/xllm/api_service/embedding_service_impl.cpp @@ -94,6 +94,7 @@ void EmbeddingServiceImpl::process_async_impl( // TODO only support input_str for now auto& input = rpc_request.input(); + auto saved_request_id = request_params.request_id; // schedule the request master_->handle_request( std::move(input), @@ -102,7 +103,7 @@ void EmbeddingServiceImpl::process_async_impl( call.get(), [call, model, - request_id = request_params.request_id, + request_id = std::move(saved_request_id), created_time = absl::ToUnixSeconds(absl::Now())]( const RequestOutput& req_output) -> bool { if (req_output.status.has_value()) { diff --git a/xllm/api_service/image_generation_service_impl.cpp b/xllm/api_service/image_generation_service_impl.cpp index 5767e4b58..ed79c6eb4 100644 --- a/xllm/api_service/image_generation_service_impl.cpp +++ b/xllm/api_service/image_generation_service_impl.cpp @@ -83,13 +83,14 @@ void ImageGenerationServiceImpl::process_async_impl( DiTRequestParams request_params( rpc_request, call->get_x_request_id(), call->get_x_request_time()); + auto saved_request_id = request_params.request_id; // schedule the request master_->handle_request( std::move(request_params), call.get(), [call, model, - request_id = request_params.request_id, + request_id = std::move(saved_request_id), created_time = absl::ToUnixSeconds(absl::Now())]( const DiTRequestOutput& req_output) -> bool { if (req_output.status.has_value()) {