From a4109779aced389d04b355591a730733cd2cc8ff Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Wed, 31 Jul 2024 15:33:20 +0200 Subject: [PATCH] fix: Ensure BoardListWatch gRPC call correctly release resources --- commands/service_board_list.go | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/commands/service_board_list.go b/commands/service_board_list.go index 44e89fdc8dd..2b124c29f37 100644 --- a/commands/service_board_list.go +++ b/commands/service_board_list.go @@ -282,20 +282,14 @@ func (s *arduinoCoreServerImpl) BoardListWatch(req *rpc.BoardListWatchRequest, s if err != nil { return err } - defer release() dm := pme.DiscoveryManager() watcher, err := dm.Watch() + release() if err != nil { return err } - go func() { - <-stream.Context().Done() - logrus.Trace("closed watch") - watcher.Close() - }() - go func() { for event := range watcher.Feed() { port := &rpc.DetectedPort{ @@ -319,5 +313,7 @@ func (s *arduinoCoreServerImpl) BoardListWatch(req *rpc.BoardListWatchRequest, s }() <-stream.Context().Done() + logrus.Trace("closed watch") + watcher.Close() return nil }