From f3f01227e94235d352f14c6e318ff4e11ad6abb9 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Thu, 14 Sep 2023 15:17:30 +0200 Subject: [PATCH] Fix some rare IOServiceGetMatchingServices failure on MacOSX We had reports of users always getting: IOServiceGetMatchingServices failed, data changed while iterating The issue seems related to the function getMatchingServices that returns an always-invalid iterator even if there are no actual services. This is a workaround for this issue. --- enumerator/usb_darwin.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/enumerator/usb_darwin.go b/enumerator/usb_darwin.go index 2e653ec..d9adb1b 100644 --- a/enumerator/usb_darwin.go +++ b/enumerator/usb_darwin.go @@ -97,8 +97,8 @@ func getAllServices(serviceType string) ([]io_object_t, error) { services = append(services, service) continue } - // If iterator is still valid return the result - if i.IsValid() { + // If the list of services is empty or the iterator is still valid return the result + if len(services) == 0 || i.IsValid() { return services, nil } // Otherwise empty the result and retry