Better error handling
See original GitHub issueI’ve had CCXWS running on multiple exchanges and assets for a while now, and recently noticed that some exchanges (Binance in this case) will throw an error and cause my script to crash, even with a try catch around it. Below is the snippet I receive. I am trying to add logic to my code so I can catch this error and handle it myself and believe this is a bug. If it isn’t, please let me know how to handle it as there doesn’t appear to be any documentation and what I’ve tried so far hasn’t worked (try catch and websocket.on(‘error’)).
`info: watcher initiating reconnection info: reconnecting info: closing connection to wss://stream.binance.com:9443/stream?streams=bnbusdt@aggTrade info: attempting connection info: connecting to wss://stream.binance.com:9443/stream?streams=bnbusdt@aggTrade events.js:183 throw er; // Unhandled ‘error’ event ^
RangeError: Invalid WebSocket frame: invalid status code 1005 at Receiver.controlMessage (/var/www/html/discord-node/node_modules/ccxws/node_modules/ws/lib/receiver.js:441:18) at Receiver.getData (/var/www/html/discord-node/node_modules/ccxws/node_modules/ws/lib/receiver.js:329:42) at Receiver.startLoop (/var/www/html/discord-node/node_modules/ccxws/node_modules/ws/lib/receiver.js:133:22) at Receiver._write (/var/www/html/discord-node/node_modules/ccxws/node_modules/ws/lib/receiver.js:69:10) at doWrite (_stream_writable.js:397:12) at writeOrBuffer (_stream_writable.js:383:5) at Receiver.Writable.write (_stream_writable.js:290:11) at TLSSocket.socketOnData (/var/www/html/discord-node/node_modules/ccxws/node_modules/ws/lib/websocket.js:795:35) at emitOne (events.js:116:13) at TLSSocket.emit (events.js:211:7) at addChunk (_stream_readable.js:263:12) at readableAddChunk (_stream_readable.js:250:11) at TLSSocket.Readable.push (_stream_readable.js:208:10) at TLSWrap.onread (net.js:607:20) error: Forever detected script exited with code: 1 error: Script restart attempt #179`
Issue Analytics
- State:
- Created 4 years ago
- Comments:8 (5 by maintainers)
Top GitHub Comments
@kobermeit excellent!
We just pushed a new version of CCXWS that increased the watcher timeout for Binance and allows use of the
reconnectTimeoutMs
constructor argument if you need to customize it (which is a bit simpler than the workaround I previously posted). No need to update to the new version unless you want to, as the workaround will work just fine.More info: https://github.com/altangent/ccxws/releases/tag/v0.23.0
Apologies, the property was
reconnectIntervalMs
as defined here: https://github.com/altangent/ccxws/blob/master/src/exchanges/binance-client.js#L15The underlying cause of the unhandled exceptions was also recently addressed in this commit: https://github.com/altangent/ccxws/commit/a5fd310d2e4d93df0f8aeb1d85b62f8ffb1ee2c7
It is available in v0.26.1+