Missing error handling in WebSockets code

in #utopian-io7 years ago (edited)

The code for sending requests via WebSockets misses proper error handling, such that problems cannot be handled in user code.

How to reproduce

  • Should be reproducible on any PC that runs Node.js
  • Disconnect from the Internet
  • Run the following code with Node.js
const steem = require("steem");
steem.api.setOptions({ url: "wss://steemd.privex.io" });
steem.api.getAccounts(["nafestw"], (err, resp) => {
  console.log("Callback is called. err = " + err);
});

Expected behavior

The callback is called with err set to an object describing the error, which should be printed to the console.

Actual behavior

The following error occurs and the callback function is not called.

Unhandled rejection Error: getaddrinfo ENOTFOUND steemd.privex.io steemd.privex.io:443
    at errnoException (dns.js:55:10)
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:97:26)

Suggested Fix

Adding the missing .catch in src/api/transports/ws.js should fix the problem:

diff --git a/src/api/transports/ws.js b/src/api/transports/ws.js
index 863ec4f..814d701 100644
--- a/src/api/transports/ws.js
+++ b/src/api/transports/ws.js
@@ -94,7 +94,7 @@ export default class WsTransport extends Transport {
       this._requests.set(_request.message.id, _request);
       this.ws.send(JSON.stringify(_request.message));
       return deferral;
-    });
+    }).catch(err => callback(err, null));
   }

   onError(error) {



Posted on Utopian.io - Rewarding Open Source Contributors

Sort:  

Yeah was running into this problem a couple of times myself and forgot to fix the module after updating it or reinstalling it. So i have repackaged the module on npm with the fix in it.

npm install steemjs-fixed --save

Thank you for the report.


Need help? Write a ticket on https://support.utopian.io.
Chat with us on Discord.

[utopian-moderator]

Hey @nafestw! Thank you for the great work you've done!

We're already looking forward to your next contribution!

Fully Decentralized Rewards

We hope you will take the time to share your expertise and knowledge by rating contributions made by others on Utopian.io to help us reward the best contributions together.

Utopian Witness!

Vote for Utopian Witness! We are made of developers, system administrators, entrepreneurs, artists, content creators, thinkers. We embrace every nationality, mindset and belief.

Want to chat? Join us on Discord https://discord.me/utopian-io

Coin Marketplace

STEEM 0.26
TRX 0.20
JST 0.039
BTC 95566.16
ETH 3591.48
USDT 1.00
SBD 3.83