From 83110891fd0f1fd3593dfa869383a23648531acf Mon Sep 17 00:00:00 2001 From: Ettore Di Giacinto Date: Sat, 5 Oct 2024 00:02:00 +0200 Subject: [PATCH] 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 --- pkg/grpc/server.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkg/grpc/server.go b/pkg/grpc/server.go index 0e602a42..a387b96e 100644 --- a/pkg/grpc/server.go +++ b/pkg/grpc/server.go @@ -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