diff --git a/src/config/constants.js b/src/config/constants.js index 2d42e5a3..7f24d09f 100644 --- a/src/config/constants.js +++ b/src/config/constants.js @@ -31,7 +31,7 @@ export const GENUINE_CACHE_DELAY = intFromEnv('GENUINE_CACHE_DELAY', 1000) export const GENUINE_TIMEOUT = intFromEnv('GENUINE_TIMEOUT', 120 * 1000) export const GET_CALLS_RETRY = intFromEnv('GET_CALLS_RETRY', 2) export const GET_CALLS_TIMEOUT = intFromEnv('GET_CALLS_TIMEOUT', 30 * 1000) -export const LISTEN_DEVICES_POLLING_INTERVAL = intFromEnv('LISTEN_DEVICES_POLLING_INTERVAL', 100) +export const LISTEN_DEVICES_POLLING_INTERVAL = intFromEnv('LISTEN_DEVICES_POLLING_INTERVAL', 500) export const OUTDATED_CONSIDERED_DELAY = intFromEnv('OUTDATED_CONSIDERED_DELAY', 5 * 60 * 1000) export const SYNC_ALL_INTERVAL = 120 * 1000 export const SYNC_BOOT_DELAY = 2 * 1000 diff --git a/src/helpers/deviceAccess.js b/src/helpers/deviceAccess.js index 590fdddc..fe9b95e1 100644 --- a/src/helpers/deviceAccess.js +++ b/src/helpers/deviceAccess.js @@ -22,17 +22,26 @@ const mapError = e => { let queue = Promise.resolve() +let busy = false + +TransportNodeHid.setListenDevicesPollingSkip(() => busy) + export const withDevice: WithDevice = devicePath => job => { const p = queue.then(async () => { - const t = await retry(() => TransportNodeHid.open(devicePath), { maxRetry: 1 }) - if (DEBUG_DEVICE) { - t.setDebugMode(true) - } + busy = true try { - const res = await job(t).catch(mapError) - return res + const t = await retry(() => TransportNodeHid.open(devicePath), { maxRetry: 1 }) + if (DEBUG_DEVICE) { + t.setDebugMode(true) + } + try { + const res = await job(t).catch(mapError) + return res + } finally { + await t.close() + } } finally { - await t.close() + busy = false } }) diff --git a/yarn.lock b/yarn.lock index 42142ddb..3186ed48 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1501,7 +1501,14 @@ "@ledgerhq/hw-transport" "^4.15.0" bip32-path "0.4.2" -"@ledgerhq/hw-transport-node-hid@^4.13.0", "@ledgerhq/hw-transport-node-hid@^4.7.6": +"@ledgerhq/hw-transport-node-hid@^4.13.0": + version "4.18.0" + resolved "https://registry.yarnpkg.com/@ledgerhq/hw-transport-node-hid/-/hw-transport-node-hid-4.18.0.tgz#39ab0f9300c755f6b33f28dda22e30677882b6be" + dependencies: + "@ledgerhq/hw-transport" "^4.15.0" + node-hid "^0.7.2" + +"@ledgerhq/hw-transport-node-hid@^4.7.6": version "4.16.0" resolved "https://registry.yarnpkg.com/@ledgerhq/hw-transport-node-hid/-/hw-transport-node-hid-4.16.0.tgz#de8d7ffd37e01c77aed566d8c534fe3937c3c35c" dependencies: @@ -9849,7 +9856,7 @@ mute-stream@0.0.7, mute-stream@~0.0.4: version "0.0.7" resolved "https://registry.yarnpkg.com/mute-stream/-/mute-stream-0.0.7.tgz#3075ce93bc21b8fab43e1bc4da7e8115ed1e7bab" -nan@^2.2.1, nan@^2.6.2, nan@^2.9.2: +nan@^2.10.0, nan@^2.2.1, nan@^2.6.2, nan@^2.9.2: version "2.10.0" resolved "https://registry.yarnpkg.com/nan/-/nan-2.10.0.tgz#96d0cd610ebd58d4b4de9cc0c6828cda99c7548f" @@ -9956,12 +9963,12 @@ node-gyp@^3.6.0, node-gyp@^3.6.2: which "1" node-hid@^0.7.2: - version "0.7.2" - resolved "https://registry.yarnpkg.com/node-hid/-/node-hid-0.7.2.tgz#15025cdea2e9756aca2de7266529996d40e52c56" + version "0.7.3" + resolved "https://registry.yarnpkg.com/node-hid/-/node-hid-0.7.3.tgz#736e9a4dee5eec96c20fbe301e0311bb185cb2f4" dependencies: bindings "^1.3.0" - nan "^2.6.2" - prebuild-install "^2.2.2" + nan "^2.10.0" + prebuild-install "^4.0.0" node-int64@^0.4.0: version "0.4.0" @@ -11279,6 +11286,26 @@ prebuild-install@^2.0.0, prebuild-install@^2.2.2: tunnel-agent "^0.6.0" which-pm-runs "^1.0.0" +prebuild-install@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/prebuild-install/-/prebuild-install-4.0.0.tgz#206ce8106ce5efa4b6cf062fc8a0a7d93c17f3a8" + dependencies: + detect-libc "^1.0.3" + expand-template "^1.0.2" + github-from-package "0.0.0" + minimist "^1.2.0" + mkdirp "^0.5.1" + node-abi "^2.2.0" + noop-logger "^0.1.1" + npmlog "^4.0.1" + os-homedir "^1.0.1" + pump "^2.0.1" + rc "^1.1.6" + simple-get "^2.7.0" + tar-fs "^1.13.0" + tunnel-agent "^0.6.0" + which-pm-runs "^1.0.0" + prelude-ls@~1.1.2: version "1.1.2" resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.1.2.tgz#21932a549f5e52ffd9a827f570e04be62a97da54"