@@ -574,9 +574,10 @@ ModelStreamInferHandler::StreamInferResponseComplete(
574
574
#endif // TRITON_ENABLE_TRACING
575
575
576
576
// Log appropriate errors
577
- state->complete_ = ((flags & TRITONSERVER_RESPONSE_COMPLETE_FINAL) != 0 );
577
+ bool is_complete =
578
+ state->complete_ || (flags & TRITONSERVER_RESPONSE_COMPLETE_FINAL) != 0 ;
578
579
if (!state->is_decoupled_ ) {
579
- if (!state-> complete_ ) {
580
+ if (!is_complete ) {
580
581
LOG_ERROR << " [INTERNAL] ModelStreamInfer received a response without "
581
582
" FINAL flag for a model with one-to-one transaction" ;
582
583
}
@@ -591,7 +592,7 @@ ModelStreamInferHandler::StreamInferResponseComplete(
591
592
// Also make sure that if this state was sent to gRPC async notification
592
593
// mechanism then the state is not removed as it would be needed for handling
593
594
// the cancellation if detected.
594
- if (state-> complete_ && (!state->IsAsyncNotifyState ())) {
595
+ if (is_complete && (!state->IsAsyncNotifyState ())) {
595
596
state->context_ ->EraseInflightState (state);
596
597
}
597
598
@@ -610,11 +611,12 @@ ModelStreamInferHandler::StreamInferResponseComplete(
610
611
// If this was the final callback for the state
611
612
// then cycle through the completion queue so
612
613
// that state object can be released.
613
- if (state-> complete_ ) {
614
+ if (is_complete ) {
614
615
state->step_ = Steps::CANCELLED;
615
616
state->context_ ->PutTaskBackToQueue (state);
616
617
}
617
618
619
+ state->complete_ = is_complete;
618
620
return ;
619
621
}
620
622
@@ -661,8 +663,7 @@ ModelStreamInferHandler::StreamInferResponseComplete(
661
663
// "empty" responses are not sent back to the client. Clients can
662
664
// opt-in to receiving these empty responses via request parameters.
663
665
// NOTE: The complete flag is the only flag used for this case at this time.
664
- const bool empty_final =
665
- (!iresponse && state->is_decoupled_ && state->complete_ );
666
+ const bool empty_final = !iresponse && state->is_decoupled_ && is_complete;
666
667
const bool enable_empty_final =
667
668
state->parameters_ .enable_empty_final_response_ ;
668
669
@@ -690,7 +691,24 @@ ModelStreamInferHandler::StreamInferResponseComplete(
690
691
infer_response.set_model_version (state->request_ .model_version ());
691
692
}
692
693
auto & params = *(infer_response.mutable_parameters ());
693
- params[" triton_final_response" ].set_bool_param (state->complete_ );
694
+ params[" triton_final_response" ].set_bool_param (is_complete);
695
+ }
696
+
697
+ if (state->delay_complete_ms_ != 0 ) {
698
+ // Delay updating the state. This is useful for testing race condition with
699
+ // the thread that runs Process().
700
+ LOG_INFO << " Delaying the completion of reporting response / flag by "
701
+ << state->delay_complete_ms_ << " ms..." ;
702
+ void * context_ptr_before_delay = (void *)state->context_ .get ();
703
+ std::this_thread::sleep_for (
704
+ std::chrono::milliseconds (state->delay_complete_ms_ ));
705
+ void * context_ptr_after_delay = (void *)state->context_ .get ();
706
+ if (context_ptr_before_delay != context_ptr_after_delay) {
707
+ LOG_ERROR << " Should not print this! The state context object has "
708
+ " changed after delay, pointer before: "
709
+ << context_ptr_before_delay
710
+ << " , pointer after: " << context_ptr_after_delay;
711
+ }
694
712
}
695
713
696
714
// Update states to signal that response/error is ready to write to stream
@@ -708,11 +726,12 @@ ModelStreamInferHandler::StreamInferResponseComplete(
708
726
// If this was the final callback for the state
709
727
// then cycle through the completion queue so
710
728
// that state object can be released.
711
- if (state-> complete_ ) {
729
+ if (is_complete ) {
712
730
state->step_ = Steps::CANCELLED;
713
731
state->context_ ->PutTaskBackToQueue (state);
714
732
}
715
733
734
+ state->complete_ = is_complete;
716
735
return ;
717
736
}
718
737
@@ -728,6 +747,8 @@ ModelStreamInferHandler::StreamInferResponseComplete(
728
747
state->step_ = Steps::WRITEREADY;
729
748
state->context_ ->WriteResponseIfReady (state);
730
749
}
750
+
751
+ state->complete_ = is_complete;
731
752
}
732
753
}
733
754
0 commit comments