question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bittrex tries to access this._subCount when sub/unsub but its undefined, throws error

See original GitHub issue

ccxws v 0.27.2

Exchange Bittrex

Subscription type level2 orderbook updates

Describe the bug It looks like the Bittrex client is trying to access the internal this._subCount property but it’s undefined (perhaps it needs to be bound for the correct this).

Bittrex ccxws websocket error: No Hub
Cannot read property 'BTC-EOS' of undefined
    at BittrexClient._sendSub (/home/evan/devel/coygo/webapp/.meteor/desktop-build/node_modules/ccxws/src/exchanges/bittrex-client.js:126:48)
    at BittrexClient._subscribe (/home/evan/devel/coygo/webapp/.meteor/desktop-build/node_modules/ccxws/src/exchanges/bittrex-client.js:108:14)
    at BittrexClient.subscribeLevel2Updates (/home/evan/devel/coygo/webapp/.meteor/desktop-build/node_modules/ccxws/src/exchanges/bittrex-client.js:82:10)
    at classDefinition.(anonymous function).registerOrderBookListener (/home/evan/devel/coygo/webapp/.meteor/desktop-build/desktop.asar/trading/exchange-clients/ExchangeClientCcxtCcxwsCommon.js:177:16)
    at process._tickCallback (internal/process/next_tick.js:68:7)

TypeError: Cannot read property 'BTC-EOS' of undefined
    at BittrexClient._sendUnsub (/home/evan/devel/coygo/webapp/.meteor/desktop-build/node_modules/ccxws/src/exchanges/bittrex-client.js:150:20)
    at BittrexClient._unsubscribe (/home/evan/devel/coygo/webapp/.meteor/desktop-build/node_modules/ccxws/src/exchanges/bittrex-client.js:119:14)
    at BittrexClient.unsubscribeLevel2Updates (/home/evan/devel/coygo/webapp/.meteor/desktop-build/node_modules/ccxws/src/exchanges/bittrex-client.js:90:10)
    at classDefinition.(anonymous function).deregisterOrderBookListener (/home/evan/devel/coygo/webapp/.meteor/desktop-build/desktop.asar/trading/exchange-clients/ExchangeClientCcxtCcxwsCommon.js:363:16)
(node:10161) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)

The problem lines are:

 _sendSub(remote_id) {
    // increment market counter
    this._subCount[remote_id] = (this._subCount[remote_id] || 0) + 1;
_sendUnsub(remote_id) {
    // decrement market count
    this._subCount[remote_id] -= 1;
  }

To Reproduce Subscribe to l2 updates on Bittrex BTC-EOS market.

This happened once but I can’t reproduce it since then, so I just grabbed the logs to place them here in hopes that it’s enough details.

Expected behavior Connection is successful and doesn’t throw error.

Additional context Add any other context about the problem here.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
bmancini55commented, Sep 10, 2019

Two fixes are now available in release v0.27.3:

  1. Reordered connection logic to match logic in other clients
  2. Fixed a race condition on subscribe.

Most likely the second is the culprit of your issues. The calls to subscribe were checking for the existence of the websocket variable _wss https://github.com/altangent/ccxws/blob/22eafc7fc5330a7fac75be7cf62a4602a390f7c0/src/exchanges/bittrex-client.js#L118 to determine if it is ok to immediately send a subscription to the server.

_wss is created in _connect https://github.com/altangent/ccxws/blob/22eafc7fc5330a7fac75be7cf62a4602a390f7c0/src/exchanges/bittrex-client.js#L191

However, _subCount does not get set until a valid connection is established with the handler _onConnected.

This opened a window where a subscription would think the websocket was open when it was not actually open yet and when the call stack subscribeLevel2Update > _subscribe > _sendSub > occurred without actually be connected it would abend.

A new flag has been added _isConnected that gets set when the connection handler _onConnected is fired and is unset when disconnected event is fired in _onDisconnected. This flag is now checked in the subscribe method to determine if an immediate subscription can be performed.

I’m going to close this issue for now, if you’re still seeing the issue after this fix then we can reopen it.

0reactions
bmancini55commented, Sep 12, 2019

@evan-coygo v0.27.3 should be live on NPM now

Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshooting common error codes - Bittrex Support
The code you entered has either expired or is invalid. Please wait for a new code on your device and try your submission...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found