Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve cleanup of scan worker process when exiting #600

Merged
merged 1 commit into from
Oct 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions main/accounts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,7 @@ class Accounts extends EventEmitter {
}

close () {
dataScanner.stop()
dataScanner.kill()
// usbDetect.stopMonitoring()
}
Expand Down
2 changes: 1 addition & 1 deletion main/externalData/balances/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ async function loadTokenBalances (chainId, address, tokens) {
const results = await multicall(chainId).call(calls.slice(batchStart, batchEnd))
return Object.entries(results.transformed)
} catch (e) {
log.error(`unable to load token balances (batch ${batchIndex}-${batchEnd}`, e)
log.error(`unable to load token balances (batch ${batchStart}-${batchEnd}`, e)
return []
}
})
Expand Down
20 changes: 16 additions & 4 deletions main/externalData/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,20 +76,28 @@ function createWorker () {

scanWorker.on('error', err => {
if (err.code === 'ERR_IPC_CHANNEL_CLOSED') {
console.error('scan worker IPC channel closed! restarting worker')
log.error('scan worker IPC channel closed!')

kill()
setTimeout(restart, 1000 * 5)

if (heartbeat) {
log.info('restarting scan worker after IPC channel closed')
setTimeout(restart, 1000 * 5)
}
}

log.error(new Error(`scan worker error with code: ${err.code}`))
})

scanWorker.on('exit', code => {
log.warn(`scan worker exited with code ${code}, restarting worker`)
log.warn(`scan worker exited with code ${code}`)

kill()
setTimeout(restart, 1000 * 5)

if (heartbeat) {
log.info(`restarting scan worker after exiting with code ${code}`)
setTimeout(restart, 1000 * 5)
}
})

return scanWorker
Expand Down Expand Up @@ -232,6 +240,10 @@ function restart () {

function kill () {
if (scanWorker) {
const eventTypes = ['message', 'error', 'exit']

eventTypes.forEach(evt => scanWorker.removeAllListeners(evt))

scanWorker.kill()
scanWorker = null
}
Expand Down