Skip to content
Permalink
Browse files

fix(grpc): add 2 second delay before connecting to grpc streams

  • Loading branch information...
mrfelton committed Apr 24, 2019
1 parent 6f15699 commit 21fc54c6f237357953f65ed4f686fdbf78dae843
Showing with 12 additions and 2 deletions.
  1. +12 −2 services/grpc/grpcService.js
@@ -5,6 +5,7 @@ import { load } from '@grpc/proto-loader'
import lndgrpc from 'lnd-grpc'
import StateMachine from 'javascript-state-machine'
import { grpcLog } from '@zap/utils/log'
import delay from '@zap/utils/delay'
import promisifiedCall from '@zap/utils/promisifiedCall'
import waitForFile from '@zap/utils/waitForFile'
import grpcOptions from '@zap/utils/grpcOptions'
@@ -77,8 +78,17 @@ class GrpcService extends EventEmitter {
/**
* Log successful connection.
*/
async onAfterConnect() {
await this.subscribe()
onAfterConnect() {
// Wait for 2 seconds before subscribing to grpc streams.
// This gives lnd a chance to start up it's services after unlocking a wallet.
// We add this delay as in recent versions fo lnd (post 0.6.0), the channel stream is not functional immediately.
const subscribeAfterDelay = async () => {
await delay(2000)
if (this.is('connected')) {
this.subscribe()
}
}
subscribeAfterDelay()
grpcLog.info(`Connected to ${this.serviceName} gRPC service`)
}

0 comments on commit 21fc54c

Please sign in to comment.
You can’t perform that action at this time.