@@ -659,6 +659,7 @@ Stub::ProcessRequests(RequestBatch* request_batch_shm_ptr)
659659  bool  has_exception = false ;
660660  std::string error_string;
661661  std::unique_ptr<PbString> error_string_shm;
662+   std::string err_message;
662663
663664  ScopedDefer execute_finalize ([this ] { stub_message_queue_->Pop (); });
664665  ScopedDefer _ (
@@ -705,11 +706,10 @@ Stub::ProcessRequests(RequestBatch* request_batch_shm_ptr)
705706  }
706707
707708  if  (has_exception) {
708-     std::string err_message =
709-         std::string (
710-             " Failed to process the request(s) for model '"   + name_ +
711-             " ', message: "  ) +
712-         error_string;
709+     err_message = std::string (
710+                       " Failed to process the request(s) for model '"   + name_ +
711+                       " ', message: "  ) +
712+                   error_string;
713713    LOG_ERROR << err_message.c_str ();
714714    if  (!response_batch) {
715715      response_batch = shm_pool_->Construct <char >(
@@ -718,12 +718,11 @@ Stub::ProcessRequests(RequestBatch* request_batch_shm_ptr)
718718    ResponseBatch* response_batch_shm_ptr = reinterpret_cast <ResponseBatch*>(
719719        response_batch.value ().data_ .get () + sizeof (IPCMessageShm));
720720
721-     response_batch_shm_ptr =
722-         reinterpret_cast <ResponseBatch*>(response_batch.value ().data_ .get ());
723721    response_batch_shm_ptr->has_error  = true ;
724722    error_string_shm = PbString::Create (shm_pool_, err_message);
725723    response_batch_shm_ptr->error  = error_string_shm->ShmHandle ();
726724    response_batch_shm_ptr->is_error_set  = true ;
725+     response_batch_shm_ptr->batch_size  = 0 ;
727726    //  Once the error is sent to the backend, the backend is supposed to close
728727    //  all response factories if not already closed, so closing all response
729728    //  senders if not already closed to prevent the model from sending more
@@ -732,23 +731,25 @@ Stub::ProcessRequests(RequestBatch* request_batch_shm_ptr)
732731      InferRequest* request = py_request.cast <InferRequest*>();
733732      request->GetResponseSender ()->Close ();
734733    }
735-   }
736- 
737-   if  (!response_batch) {
738-     response_batch = shm_pool_->Construct <char >(
739-         sizeof (ResponseBatch) + sizeof (IPCMessageShm));
734+   } else  {
735+     if  (!response_batch) {
736+       response_batch = shm_pool_->Construct <char >(
737+           sizeof (ResponseBatch) + sizeof (IPCMessageShm));
738+       ResponseBatch* response_batch_shm_ptr = reinterpret_cast <ResponseBatch*>(
739+           response_batch.value ().data_ .get () + sizeof (IPCMessageShm));
740+       response_batch_shm_ptr->batch_size  = 0 ;
741+     }
740742    ResponseBatch* response_batch_shm_ptr = reinterpret_cast <ResponseBatch*>(
741743        response_batch.value ().data_ .get () + sizeof (IPCMessageShm));
742-     response_batch_shm_ptr->batch_size  = 0 ;
744+     response_batch_shm_ptr->has_error  = false ;
745+     response_batch_shm_ptr->is_error_set  = false ;
743746  }
744-   ResponseBatch* response_batch_shm_ptr = reinterpret_cast <ResponseBatch*>(
745-       response_batch.value ().data_ .get () + sizeof (IPCMessageShm));
746-   response_batch_shm_ptr->has_error  = false ;
747-   response_batch_shm_ptr->is_error_set  = false ;
747+ 
748748  execute_response = IPCMessage::Create (
749749      reinterpret_cast <IPCMessageShm*>(response_batch.value ().data_ .get ()),
750750      response_batch.value ().handle_ );
751-   execute_response->Args () = response_batch.value ().handle_ ;
751+   execute_response->Args () =
752+       response_batch.value ().handle_  + sizeof (IPCMessageShm);
752753  execute_response->InlineResponse () = false ;
753754  execute_response->Command () = PYTHONSTUB_ExecuteResponse;
754755  _.Complete ();
0 commit comments