zhangyachen commented on issue #2665:
URL: https://github.com/apache/brpc/issues/2665#issuecomment-2185473446

   
这个问题解决了,当我把上游换成grpc框架时,还是会出现不能退出的问题,确定是我代码写的有问题。后来从[server.md](https://github.com/apache/brpc/blob/master/docs/cn/server.md#%E5%81%9C%E6%AD%A2)中找到了答案,这里面提到:
   > 如果你的server“退不掉”,很有可能是由于某个检索线程没结束或忘记调用done了。
   
   我的brpc server代码是调用一个异步函数,这个异步函数在程序退出时会返回error。伪代码是:
   ```c++
   void InferenceServiceImpl::ModelInfer(google::protobuf::RpcController* 
cntl_base,
                         const inference::ModelInferRequest* request,
                         inference::ModelInferResponse* response,
                         google::protobuf::Closure* done) {
         brpc::ClosureGuard done_guard(done);
         brpc::Controller* cntl = static_cast<brpc::Controller*>(cntl_base);
         TRITONSERVER_Error* err = nullptr;
   
         //将done保存起来,在回调函数中使用
         State* state = StateNew(done, response, cntl);
         // 回调函数
        err = TRITONSERVER_InferenceRequestSetResponseCallback(
               irequest, allocator_,
               &state->alloc_payload_ /* response_allocator_userp */,
               InferResponseComplete, reinterpret_cast<void*>(state));
         // 异步函数
         if (err == nullptr) {
           err = TRITONSERVER_ServerInferAsync(tritonserver_.get(), irequest, 
nullptr);
         }
         if (err != nullptr) {
           int brpc_status;
           BrpcStatusUtil::Create(&brpc_status, err);
           std::string error_msg = berror(brpc_status);
           cntl->SetFailed(brpc_status, "%s", error_msg.c_str());
           TRITONSERVER_ErrorDelete(err);
           
           // 新添加的
           return;
         }
   
         done_guard.release();
   }
   ```
   
   
当异步函数TRITONSERVER_ServerInferAsync报错时,没有return导致brpc::ClosureGuard没有调用done->Run();


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@brpc.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@brpc.apache.org
For additional commands, e-mail: dev-h...@brpc.apache.org

Reply via email to