Browse Source

Revert "fix(lnd): ensure graceful shutdown"

This reverts commit ef7a9ad69a.
renovate/lint-staged-8.x
Tom Kirkpatrick 7 years ago
parent
commit
db2e90344d
No known key found for this signature in database GPG Key ID: 72203A8EC5967EA8
  1. 15
      app/lib/lnd/lightning.js
  2. 39
      app/lib/zap/controller.js

15
app/lib/lnd/lightning.js

@ -94,21 +94,6 @@ class Lightning {
}
}
/**
* Gracegfully shutdown the gRPC service.
*/
shutdown() {
this.unsubscribe()
return new Promise((resolve, reject) => {
this.lnd.stopDaemon({}, (err, data) => {
if (err) {
reject(err)
}
resolve(data)
})
})
}
/**
* Hook up lnd restful methods.
*/

39
app/lib/zap/controller.js

@ -127,7 +127,7 @@ class ZapController {
// FSM Callbacks
// ------------------------------------
async onOnboarding() {
onOnboarding() {
mainLog.debug('[FSM] onOnboarding...')
// Remove any existing IPC listeners so that we can start fresh.
@ -136,8 +136,13 @@ class ZapController {
// Register IPC listeners so that we can react to instructions coming from the app.
this._registerIpcListeners()
// Disconnect from any existing connection.
await this.disconnectLightningWallet()
// Ensure wallet is disconnected.
this.disconnectLightningWallet()
// If Neutrino is running, kill it.
if (this.neutrino) {
this.neutrino.stop()
}
// Give the grpc connections a chance to be properly closed out.
return new Promise(resolve => setTimeout(resolve, 200))
@ -204,9 +209,16 @@ class ZapController {
})
}
async onTerminated() {
onTerminated() {
mainLog.debug('[FSM] onTerminated...')
await this.disconnectLightningWallet()
// Unsubscribe the gRPC streams before thhe window closes. This ensures that we can properly reestablish a fresh
// connection when a new window is opened.
this.disconnectLightningWallet()
// If Neutrino is running, kill it.
if (this.neutrino) {
this.neutrino.stop()
}
}
onTerminate() {
@ -263,10 +275,10 @@ class ZapController {
* Create and subscribe to the Lightning service.
*/
async startLightningWallet() {
mainLog.info('Starting lightning wallet...')
if (this.lightningGrpcConnected) {
return
}
mainLog.info('Starting lightning wallet...')
this.lightning = new Lightning()
// Connect to the Lightning interface.
@ -288,23 +300,14 @@ class ZapController {
/**
* Unsubscribe from the Lightning service.
*/
async disconnectLightningWallet() {
mainLog.info('Shutting down lightning Wallet...')
disconnectLightningWallet() {
if (!this.lightningGrpcConnected) {
return
}
mainLog.info('Disconnecting lightning Wallet...')
// Shutdown / disconnect from the lnd instance.
try {
if (this.neutrino) {
await this.lightning.shutdown()
this.neutrino.stop()
} else if (this.lightning) {
// Disconnect streams.
this.lightning.disconnect()
}
} catch (e) {
mainLog.error('There was a problem when trying to shutdown lnd', e)
}
// Update our internal state.
this.lightningGrpcConnected = false

Loading…
Cancel
Save