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.

Doesn't work for GDAX (node)

See original GitHub issue

The module doesn’t manage to stay connected to the [GDAX] crypto data feed:

const WebSocket = require('ws');
const ReconnectingWebSocket = require('reconnecting-websocket');
const rws = new ReconnectingWebSocket('wss://ws-feed.gdax.com', [], {
  constructor: WebSocket,
  debug: true,
});

let lastPointTimestamp = new Date();
setInterval(() => {
  if (Date.now() - lastPointTimestamp > 60 * 1000)
    // No data in the past minute since we got called
    console.warn('Got disconnected and did not reconnect');
}, 60 * 1000);

function handleData(data) {
  lastPointTimestamp = Date.now();
  console.log(data.price);
}

rws.on('open', () => {
  rws.send(JSON.stringify({
    type: 'subscribe',
    product_ids: ['BTC-USD'],
    channels: ['matches'],
  }));
});
rws.on('message', data => handleData(JSON.parse(data)));
rws.on('error', err => {
  console.error('ON ERROR -', err);
});

The log shows this:

ON ERROR - { Error: read ECONNRESET
    at _errnoException (util.js:1003:13)
    at TLSWrap.onread (net.js:620:25) errno: 'ECONNRESET', code: 'ECONNRESET', syscall: 'read' }
RWS: handleClose { shouldRetry: true }
RWS: retries count: 1
RWS: handleClose - reconnectDelay: 2043.1049894719274
RWS: connect
RWS: bypass properties
RWS: timeout

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
pladariacommented, Jan 17, 2018

Happy to hear that!

ReconnectingWebsocket uses the standard WebSocket API

you can use .addEventListener or assign a function to onopen: rws.onopen = () => console.log('open');

1reaction
kinsi55commented, Jan 14, 2018

I have exactly the same issue with Twitch PubSub.

RWS: handleClose { shouldRetry: true }
RWS: retries count: 1
RWS: handleClose - reconnectDelay: 2125.6480950789783
RWS: connect
RWS: bypass properties
RWS: timeout

Edit: Looks like i’ve found the Culprit. In the connect function, a handler for ‘close’ is created which calls the handleClose function, which then tries to reconnect by calling connect after a delay. The issue is that the connect function has a timeout delay which does not try to reconnect upon timeout, thus it stalls. Lemme whip up a fix.

Read more comments on GitHub >

github_iconTop Results From Across the Web

node.js - GDAX websocket freezing - Stack Overflow
js GDAX library. I have an implementation that works fairly well however the websocket is randomly freezing with no close event emitted.i have...
Read more >
gdax - npm
Client for the GDAX API. Latest version: 0.9.0, last published: 4 years ago. Start using gdax in your project by running `npm i...
Read more >
Gdax NPM | npm.io
The official Node.js library for Coinbase's Pro API. Features. Easy functionality to use in programmatic trading; A customizable, websocket-synced Order Book ...
Read more >
DAX cluster components - Amazon DynamoDB
DAX spreads the load evenly across all the nodes in the cluster. (Another way to increase throughput is to use larger cache node...
Read more >
FAQ on API - Coinbase Help
The primary data sources and servers for Coinbase are run in the Amazon US East ... We have three official client libraries: Node.js,...
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