Skip to content

Commit

Permalink
fix: Ensure calls to BoardListWatch gRPC correctly release resources (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
cmaglie authored Jul 31, 2024
1 parent 43598fc commit faa6359
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions commands/service_board_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -319,5 +313,7 @@ func (s *arduinoCoreServerImpl) BoardListWatch(req *rpc.BoardListWatchRequest, s
}()

<-stream.Context().Done()
logrus.Trace("closed watch")
watcher.Close()
return nil
}

0 comments on commit faa6359

Please sign in to comment.