XRPLF / xrpl.js

A JavaScript/TypeScript API for interacting with the XRP Ledger in Node.js and the browser
https://xrpl.org/
1.2k stars 511 forks source link

UnhandledPromiseRejectionWarning in Connection class _heartbeat interval #1178

Closed nickewansmith closed 4 years ago

nickewansmith commented 4 years ago

This seems to make itself apparent on attempts to reconnect with no chance of success in a reasonable time period.

It looks like on https://github.com/ripple/ripple-lib/blob/27abc10d93237df6284e67c5cfc0d42a61061412/src/common/connection.ts#L374 the possible rejection of this.reconnect() is not handled in the catch block.

This can be duplicated in this way:

const RippleAPI = require('ripple-lib').RippleAPI;

const api = new RippleAPI({
  server: 'wss://s.altnet.rippletest.net:51233' 
});

const run = async () => {
  api.connection.connect = async function () {
    throw new Error('error on connect');
  }
  setInterval( () => api.connection._heartbeat(), 1000);
}

run()
  .then(() => {
    console.log('Success');
  })
  .catch((e) => {
    console.error('Caught', e);
  });
nickewansmith commented 4 years ago

Proposed fix for this issue https://github.com/ripple/ripple-lib/pull/1179

nickewansmith commented 4 years ago

Closing thx!