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 }