You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using this API, occassionally (~once a day), my application crashes due to the API trying to send over the websocket while the websocket is in a closed state:
Due to the asynchronous nature of the ticker subscription, I cannot catch the thrown exception in my own code as far as I'm aware, so I'm a sitting duck for these crashes. The problem occurs in the following piece of code:
constdoSendPublic=function(ws,message){debugToConsole('SENT: '+message)ws.send(message)}constdoSendPrivate=function(ws,message){if(apiKey===''){errorToConsole('You did not set the API key, but requested a private function.')return}if(this.authenticated){debugToConsole('SENT: '+message)ws.send(message)}else{waitForSocketPrivate(ws,()=>{debugToConsole('SENT: '+message)ws.send(message)})}}
The three ws.send commands should either pass a callback as third parameter, or be wrapped in a try-catch-block, to intercept the error. I'm willing to write a PR if you want. ws.send signature:
/** * Send a data message. * * @param {*} data The message to send * @param {Object} options Options object * @param {Boolean} options.compress Specifies whether or not to compress `data` * @param {Boolean} options.binary Specifies whether `data` is binary or text * @param {Boolean} options.fin Specifies whether the fragment is the last one * @param {Boolean} options.mask Specifies whether or not to mask `data` * @param {Function} cb Callback which is executed when data is written out * @public */send(data,options,cb){
This triggers the error in the ws.send method:
if(this.readyState!==WebSocket.OPEN){consterr=newError(`WebSocket is not open: readyState ${this.readyState} `+`(${readyStates[this.readyState]})`);if(cb)returncb(err);throwerr;}
The text was updated successfully, but these errors were encountered:
roerdinkholder
changed the title
Catch error in ws.send when websocket is not open
Catch error in ws.send when WebSocket is not in an open-state
May 16, 2021
When using this API, occassionally (~once a day), my application crashes due to the API trying to send over the websocket while the websocket is in a closed state:
Due to the asynchronous nature of the ticker subscription, I cannot catch the thrown exception in my own code as far as I'm aware, so I'm a sitting duck for these crashes. The problem occurs in the following piece of code:
The three
ws.send
commands should either pass a callback as third parameter, or be wrapped in a try-catch-block, to intercept the error. I'm willing to write a PR if you want.ws.send
signature:This triggers the error in the
ws.send
method:The text was updated successfully, but these errors were encountered: