Browse Source

not multiple LND reconnect retires

feature/dockerfile-arm v0.8.18
Evan Feenstra 5 years ago
parent
commit
042a0ba1ef
  1. 17
      api/grpc/index.ts
  2. 17
      dist/api/grpc/index.js
  3. 2
      dist/api/grpc/index.js.map

17
api/grpc/index.ts

@ -175,7 +175,8 @@ function subscribeInvoices(actions) {
console.log("Status", status); console.log("Status", status);
// The server is unavailable, trying to reconnect. // The server is unavailable, trying to reconnect.
if (status.code == ERR_CODE_UNAVAILABLE || status.code == ERR_CODE_STREAM_REMOVED) { if (status.code == ERR_CODE_UNAVAILABLE || status.code == ERR_CODE_STREAM_REMOVED) {
reconnectToLND(); i = 0
reconnectToLND(Math.random());
} else { } else {
resolve(status); resolve(status);
} }
@ -183,7 +184,8 @@ function subscribeInvoices(actions) {
call.on('error', function(err){ call.on('error', function(err){
console.error(err) console.error(err)
if (err.code == ERR_CODE_UNAVAILABLE || err.code == ERR_CODE_STREAM_REMOVED) { if (err.code == ERR_CODE_UNAVAILABLE || err.code == ERR_CODE_STREAM_REMOVED) {
reconnectToLND(); i = 0
reconnectToLND(Math.random());
} else { } else {
reject(err) reject(err)
} }
@ -192,7 +194,8 @@ function subscribeInvoices(actions) {
const now = moment().format('YYYY-MM-DD HH:mm:ss').trim(); const now = moment().format('YYYY-MM-DD HH:mm:ss').trim();
console.log(`Closed stream ${now}`); console.log(`Closed stream ${now}`);
// The server has closed the stream. // The server has closed the stream.
reconnectToLND() i = 0
reconnectToLND(Math.random())
}) })
setTimeout(()=>{ setTimeout(()=>{
resolve(null) resolve(null)
@ -201,7 +204,9 @@ function subscribeInvoices(actions) {
} }
var i = 0 var i = 0
async function reconnectToLND(){ var ctx = 0
async function reconnectToLND(innerCtx:number){
ctx = innerCtx
i++ i++
console.log(`=> [lnd] reconnecting... attempt #${i}`) console.log(`=> [lnd] reconnecting... attempt #${i}`)
try { try {
@ -210,7 +215,9 @@ async function reconnectToLND(){
console.log(`=> [lnd] reconnected! ${now}`) console.log(`=> [lnd] reconnected! ${now}`)
} catch(e) { } catch(e) {
setTimeout(async()=>{ // retry each 2 secs setTimeout(async()=>{ // retry each 2 secs
await reconnectToLND() if(ctx===innerCtx) { // if another retry fires, then this will not run
await reconnectToLND(innerCtx)
}
},2000) },2000)
} }
} }

17
dist/api/grpc/index.js

@ -186,7 +186,8 @@ function subscribeInvoices(actions) {
console.log("Status", status); console.log("Status", status);
// The server is unavailable, trying to reconnect. // The server is unavailable, trying to reconnect.
if (status.code == ERR_CODE_UNAVAILABLE || status.code == ERR_CODE_STREAM_REMOVED) { if (status.code == ERR_CODE_UNAVAILABLE || status.code == ERR_CODE_STREAM_REMOVED) {
reconnectToLND(); i = 0;
reconnectToLND(Math.random());
} }
else { else {
resolve(status); resolve(status);
@ -195,7 +196,8 @@ function subscribeInvoices(actions) {
call.on('error', function (err) { call.on('error', function (err) {
console.error(err); console.error(err);
if (err.code == ERR_CODE_UNAVAILABLE || err.code == ERR_CODE_STREAM_REMOVED) { if (err.code == ERR_CODE_UNAVAILABLE || err.code == ERR_CODE_STREAM_REMOVED) {
reconnectToLND(); i = 0;
reconnectToLND(Math.random());
} }
else { else {
reject(err); reject(err);
@ -205,7 +207,8 @@ function subscribeInvoices(actions) {
const now = moment().format('YYYY-MM-DD HH:mm:ss').trim(); const now = moment().format('YYYY-MM-DD HH:mm:ss').trim();
console.log(`Closed stream ${now}`); console.log(`Closed stream ${now}`);
// The server has closed the stream. // The server has closed the stream.
reconnectToLND(); i = 0;
reconnectToLND(Math.random());
}); });
setTimeout(() => { setTimeout(() => {
resolve(null); resolve(null);
@ -214,8 +217,10 @@ function subscribeInvoices(actions) {
} }
exports.subscribeInvoices = subscribeInvoices; exports.subscribeInvoices = subscribeInvoices;
var i = 0; var i = 0;
function reconnectToLND() { var ctx = 0;
function reconnectToLND(innerCtx) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
ctx = innerCtx;
i++; i++;
console.log(`=> [lnd] reconnecting... attempt #${i}`); console.log(`=> [lnd] reconnecting... attempt #${i}`);
try { try {
@ -225,7 +230,9 @@ function reconnectToLND() {
} }
catch (e) { catch (e) {
setTimeout(() => __awaiter(this, void 0, void 0, function* () { setTimeout(() => __awaiter(this, void 0, void 0, function* () {
yield reconnectToLND(); if (ctx === innerCtx) {
yield reconnectToLND(innerCtx);
}
}), 2000); }), 2000);
} }
}); });

2
dist/api/grpc/index.js.map

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save