node-binance-api icon indicating copy to clipboard operation
node-binance-api copied to clipboard

Library crashes process on some network errors

Open CherryDT opened this issue 5 years ago • 8 comments

This library throws an asynchronous error which crashes the entire process when the network becomes unstable. This is very unexpected and there doesn't seem to be a way to prevent it (there is no error callback option or anything like that).

It is caused by these lines:

https://github.com/jaggedsoft/node-binance-api/blob/14affa13733ca788acbf8ac288481bff7e8b1931/node-binance-api.js#L3828

https://github.com/jaggedsoft/node-binance-api/blob/14affa13733ca788acbf8ac288481bff7e8b1931/node-binance-api.js#L3838

For example:

/mnt/c/Users/david/proj/*****/node_modules/node-binance-api/node-binance-api.js:3828
                            if ( err ) throw err;
                                       ^

Error: ETIMEDOUT
    at Timeout.<anonymous> (/mnt/c/Users/david/proj/*****/node_modules/request/request.js:848:19)
    at listOnTimeout (internal/timers.js:531:17)
    at processTimers (internal/timers.js:475:7) {
  code: 'ETIMEDOUT',
  connect: true
}

CherryDT avatar Jul 07 '20 09:07 CherryDT

Maybe it could instead just log an error and do subscription.close() to close the websocket? That would then trigger an automatic reconnect anyway.

I don't fully understand the implications though, so this is just a suggestion.

CherryDT avatar Jul 07 '20 10:07 CherryDT

I got few errors like that today too:

0|server | { Error: ETIMEDOUT 0|server | at Timeout. (/path_to_project/node_modules/request/request.js:848:19) 0|server | at ontimeout (timers.js:436:11) 0|server | at tryOnTimeout (timers.js:300:5) 0|server | at listOnTimeout (timers.js:263:5) 0|server | at Timer.processTimers (timers.js:223:10) code: 'ETIMEDOUT', connect: true }

any idea why it is happening and how to go about it ? maybe do a retry or something ?

EDIT #1. I am getting it on HTTP request to create an ORDER actually - not websocket.

evgenyfedorenko avatar Sep 18 '20 23:09 evgenyfedorenko

For a few months now, ever since their "upgrade", the Binance API has become unstable. We also see timeouts, "internal errors" and delayed internal state updates (for example: order opened successfully, but when querying status the order is not found until half a minute later) on a regular basis ever since.

You will have to build a more robust error handling logic around your calls. Especially in case of timeouts and internal error responses you cannot be sure if a) your request didn't succeed, b) your request was executed or c) your request was executed but not reflected in the API yet (until maybe a minute later). To avoid double trades or double withdrawals in this case, you have to cease trading for 2-3 minutes and then afterwards check the order list/withdrawal list APIs to see if your previous request was actually executed or not, and only if it wasn't, then you can retry the request safely*. You won't know the ID so you'll have to match the orders/withdrawals from the list based on other properties such as volume, symbol and rough timeframe.

*: "safely" is also not 100% safe here because we had delays of up to 10 minutes in some instances. But most of the time the delay is less than 2 minutes.

CherryDT avatar Oct 13 '20 10:10 CherryDT

We've also received that timeout crash issue. It's from node-binance-api still using request and not handling the on('error') event which is a different situation than the error response, this causes request to throw an exception.

On Tue, Oct 13, 2020 at 6:26 AM David Trapp [email protected] wrote:

For a few months now, ever since their "upgrade", the Binance API has become unstable. We also see timeouts, "internal errors" and delayed internal state updates (for example: order opened successfully, but when querying status the order is not found until half a minute later) on a regular basis ever since.

You will have to build a more robust error handling logic around your calls. Especially in case of timeouts and internal error responses you cannot be sure if a) your request didn't succeed, b) your request was executed or c) your request was executed but not reflected in the API yet (until maybe a minute later). To avoid double trades or double withdrawals in this case, you have to cease trading for 2-3 minutes and then afterwards check the order list/withdrawal list APIs to see if your previous request was actually executed or not.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/jaggedsoft/node-binance-api/issues/452#issuecomment-707646281, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAUBKE6WTA4IARRFB4JVSU3SKQTMJANCNFSM4OSUXKQQ .

-- Will Perone

MegaManSE avatar Oct 13 '20 13:10 MegaManSE

I started getting those more frequently now. You guys have the same situation? I wonder if that is Binance or could be something with the network.

evgenyfedorenko avatar Nov 25 '20 03:11 evgenyfedorenko

tion? I wonder if that is Binance or could be something with the network.

Same here, but how can I prevent this lib from crashing the service? Can't trace what's the cause.

blueberry6401 avatar Dec 05 '20 00:12 blueberry6401

Got this one.

Error: ETIMEDOUT
    at Timeout._onTimeout (/..../node_modules/request/request.js:849:19)
    at ontimeout (timers.js:436:11)
    at tryOnTimeout (timers.js:300:5)
    at listOnTimeout (timers.js:263:5)
    at Timer.processTimers (timers.js:223:10)

blueberry6401 avatar Dec 05 '20 01:12 blueberry6401

This is an error inside request.js that throws an exception. The library just needs to add a try catch when it makes requests, it's very simple. I've added it to my local copy of it already.

On Fri, Dec 4, 2020 at 8:24 PM blueberry6401 [email protected] wrote:

Got this one. Error: ETIMEDOUT at Timeout._onTimeout (/var/www/nami-trade/game-backend/node_modules/request/request.js:849:19) at ontimeout (timers.js:436:11) at tryOnTimeout (timers.js:300:5) at listOnTimeout (timers.js:263:5) at Timer.processTimers (timers.js:223:10)

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/jaggedsoft/node-binance-api/issues/452#issuecomment-739100547, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAUBKE2L2D7ZCS63XX47FY3STGDWBANCNFSM4OSUXKQQ .

-- Will Perone

MegaManSE avatar Dec 15 '20 15:12 MegaManSE