From faa635960f7b8e2d5a15401dfd080bc17796025e Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Wed, 31 Jul 2024 16:35:20 +0200 Subject: [PATCH] fix: Ensure calls to BoardListWatch gRPC correctly release resources (#2681) --- 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 }