fix(go-grpc-server): always close resultChan

By not closing the channel, if a server not implementing PredictStream
receives a client call would hang indefinetly as would wait for
resultChan to be consumed.

If the prediction stream returns we close the channel now and we wait
for the goroutine to finish.

Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
This commit is contained in:
Ettore Di Giacinto 2024-10-05 00:02:00 +02:00
parent 2553de0187
commit 83110891fd

View File

@ -144,6 +144,8 @@ func (s *server) PredictStream(in *pb.PredictOptions, stream pb.Backend_PredictS
}()
err := s.llm.PredictStream(in, resultChan)
// close the channel, so if resultChan is not closed by the LLM (maybe because does not implement PredictStream), the client will not hang
close(resultChan)
<-done
return err