Skip to content

Commit a410977

Browse files
committed
fix: Ensure BoardListWatch gRPC call correctly release resources
1 parent cbec871 commit a410977

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

commands/service_board_list.go

+3-7
Original file line numberDiff line numberDiff line change
@@ -282,20 +282,14 @@ func (s *arduinoCoreServerImpl) BoardListWatch(req *rpc.BoardListWatchRequest, s
282282
if err != nil {
283283
return err
284284
}
285-
defer release()
286285
dm := pme.DiscoveryManager()
287286

288287
watcher, err := dm.Watch()
288+
release()
289289
if err != nil {
290290
return err
291291
}
292292

293-
go func() {
294-
<-stream.Context().Done()
295-
logrus.Trace("closed watch")
296-
watcher.Close()
297-
}()
298-
299293
go func() {
300294
for event := range watcher.Feed() {
301295
port := &rpc.DetectedPort{
@@ -319,5 +313,7 @@ func (s *arduinoCoreServerImpl) BoardListWatch(req *rpc.BoardListWatchRequest, s
319313
}()
320314

321315
<-stream.Context().Done()
316+
logrus.Trace("closed watch")
317+
watcher.Close()
322318
return nil
323319
}

0 commit comments

Comments
 (0)