lotion icon indicating copy to clipboard operation
lotion copied to clipboard

Handle connect() api websocket disconnects

Open ameeuw opened this issue 6 years ago • 0 comments

Using the connect() api I am having trouble when the websocket to the full node disconnects. Now that in v0.1.17 the event-emitter bus is also returned by the connect() method, I am listening on errors and try to catch the ones that are "websocket disconnected" type. I then rerun the connect() method to yield a new client and work with that one but it seems to have deeper troubles in the pumpify/duplexify modules...

Where could this problem lie? Any plans on handling disconnects and maybe autoreconnect in the connect() api?

My code to handle disconnect:

let client = await lotion.connect(null, {genesis, nodes})
if (client.bus != undefined) {
  client.bus.on('error', async(err)=>{
    if (err.toString().indexOf("websocket disconnected") > -1) {
      console.log("Reconnecting...")
      client = await lotion.connect(null, {genesis, nodes})
      txServer.lc = client
    }
  })
}

ameeuw avatar Mar 29 '18 10:03 ameeuw