good morning!!!!
Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
bor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
open
bor
Commits
2fae1bde
Unverified
Commit
2fae1bde
authored
5 years ago
by
Martin Holst Swende
Committed by
Péter Szilágyi
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
account/usbwallet: abort usb enumeration after failures
parent
645756cd
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
accounts/usbwallet/hub.go
+11
-1
11 additions, 1 deletion
accounts/usbwallet/hub.go
with
11 additions
and
1 deletion
accounts/usbwallet/hub.go
+
11
−
1
View file @
2fae1bde
...
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment