From a11a22453a09088689b7a115151c60d52c21bfdf Mon Sep 17 00:00:00 2001 From: Juan Cruz Viotti Date: Fri, 20 Oct 2017 11:10:12 -0400 Subject: [PATCH] fix(usbboot): handle LIBUSB_ERROR_NO_DEVICE when claiming a USB interface (#1796) Consider the following scenario: - Usbboot runs successfully on a device - Before the block device gets a chance to appear, we run usbboot again If we're fast enough, usbboot will try to claim the device interface, but then the drive might not be there anymore, causing a `LIBUSB_ERROR_NO_DEVICE`. This commit addresses that scenario, and simply ignores the drive. Change-Type: patch Changelog-Entry: Fix `LIBUSB_ERROR_NO_DEVICE` error at the end of usbboot. Signed-off-by: Juan Cruz Viotti --- lib/shared/sdk/usbboot/index.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/shared/sdk/usbboot/index.js b/lib/shared/sdk/usbboot/index.js index bdc67738..de9db7af 100644 --- a/lib/shared/sdk/usbboot/index.js +++ b/lib/shared/sdk/usbboot/index.js @@ -400,7 +400,17 @@ exports.scan = (options) => { const deviceInterface = device.interface(addresses.interface) debug(`Claiming interface: ${addresses.interface}`) - deviceInterface.claim() + + try { + deviceInterface.claim() + } catch (error) { + if (error.message === 'LIBUSB_ERROR_NO_DEVICE') { + debug('Couldn\'t claim the interface. Assuming the device is gone') + return null + } + + throw error + } const endpoint = deviceInterface.endpoint(addresses.endpoint) @@ -429,5 +439,5 @@ exports.scan = (options) => { // See http://bluebirdjs.com/docs/api/promise.map.html }, { concurrency: 5 - }) + }).then(_.compact) }