diff options
author | Péter Szilágyi <peterke@gmail.com> | 2019-06-05 21:52:31 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-06-05 21:52:31 +0800 |
commit | 30c2b1b06dc2ae703d082a46a5316ea89da04a52 (patch) | |
tree | e9cccff5ada11a8e62cfb94248d9a93cf3ddf96a /accounts | |
parent | b8ca3cb7d2063911bb4e0a28fcb746e7e27d145d (diff) | |
parent | 2fae1bde426abd063847c10021eae7bafdc63c3d (diff) | |
download | go-tangerine-30c2b1b06dc2ae703d082a46a5316ea89da04a52.tar go-tangerine-30c2b1b06dc2ae703d082a46a5316ea89da04a52.tar.gz go-tangerine-30c2b1b06dc2ae703d082a46a5316ea89da04a52.tar.bz2 go-tangerine-30c2b1b06dc2ae703d082a46a5316ea89da04a52.tar.lz go-tangerine-30c2b1b06dc2ae703d082a46a5316ea89da04a52.tar.xz go-tangerine-30c2b1b06dc2ae703d082a46a5316ea89da04a52.tar.zst go-tangerine-30c2b1b06dc2ae703d082a46a5316ea89da04a52.zip |
Merge pull request #19671 from holiman/usbfix
account/usbwallet: abort usb enumeration after failures
Diffstat (limited to 'accounts')
-rw-r--r-- | accounts/usbwallet/hub.go | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/accounts/usbwallet/hub.go b/accounts/usbwallet/hub.go index 8f34d63e8..23be98a08 100644 --- a/accounts/usbwallet/hub.go +++ b/accounts/usbwallet/hub.go @@ -20,6 +20,7 @@ import ( "errors" "runtime" "sync" + "sync/atomic" "time" "github.com/ethereum/go-ethereum/accounts" @@ -64,6 +65,7 @@ type Hub struct { // TODO(karalabe): remove if hotplug lands on Windows commsPend int // Number of operations blocking enumeration commsLock sync.Mutex // Lock protecting the pending counter and enumeration + enumFails uint32 // Number of times enumeration has failed } // NewLedgerHub creates a new hardware wallet manager for Ledger devices. @@ -138,6 +140,10 @@ func (hub *Hub) refreshWallets() { if elapsed < refreshThrottling { return } + // If USB enumeration is continually failing, don't keep trying indefinitely + if atomic.LoadUint32(&hub.enumFails) > 2 { + return + } // Retrieve the current list of USB wallet devices var devices []usb.DeviceInfo @@ -156,13 +162,17 @@ func (hub *Hub) refreshWallets() { } infos, err := usb.Enumerate(hub.vendorID, 0) if err != nil { + failcount := atomic.AddUint32(&hub.enumFails, 1) if runtime.GOOS == "linux" { // See rationale before the enumeration why this is needed and only on Linux. hub.commsLock.Unlock() } - log.Error("error enumerating USB enumeration: ", "code", err) + log.Error("Failed to enumerate USB devices", "hub", hub.scheme, + "vendor", hub.vendorID, "failcount", failcount, "err", err) return } + atomic.StoreUint32(&hub.enumFails, 0) + for _, info := range infos { for _, id := range hub.productIDs { // Windows and Macos use UsageID matching, Linux uses Interface matching |