Connection aborted and no reconnect attempt ?
I get this error quite frequently: Connection aborted
It triggers the serviceHandlers.disconnected handler but the error is undefined.
Is there a correct way to trigger a reconnect manually with the disconnected handler ?
Using latest npm version. Any ideas ?
Many thanks
an automatic reconnection try should already be initiated, the return false on the reconnecting serviceHandler would do that, but if you need to reset it try the following:
websocketsclient.serviceHandlers.reconnecting = function (retry) {
return false;
}
for manual restarts it occurs to me that following serviceHandler methods seem more appropriate:
websocketsclient.serviceHandlers.connectionLost: function (error) {}
websocketsclient.serviceHandlers.disconnected: function () {}
It seems to run for some amount of time, several hours and then abruptly disconnects with no error and it doesn't appear to try and reconnect. I will add in serviceHandlers.reconnecting and see if that is triggered.
Is there a way to ask the current websocket sessions to be disconnected ? So if disconnected is triggered, i can just call my init function that calls websockets.subscribe again to start everything up again.
Yes, I have experienced the same thing not just with Bittrex but Poloniex, too. As described here https://github.com/websockets/ws#how-to-detect-and-close-broken-connections it's possible for a connection to be broken without the client or server knowing about it. The reasons may vary. Personally I have my script forcing disconnect/reconnect every 30 minutes.
var client;
const connect = () =>
client = new signalR.client(
"wss://socket.bittrex.com/signalr",
['CoreHub']
);
};
connect();
setInterval(() => {
client.end(); // force close the connection
connect();
}, 30*60*1000);
For Poloniex I have this at 5 minutes because I found it far more common there.
ok thanks.. will try that because i just had it again.
Here is rough transcript.. ran for 3 hours fine, then just died.
Websocket bound
Websocket connected
Subscribed to BTC-ETH
Subscribed to BTC-SC
Subscribed to BTC-XRP
Subscribed to BTC-ZEN
....
Websocket disconnected
Connection aborted
Even though i have verbose' : true and the below code, i saw no attempt to reconnect. Just stops.
bittrex_ws.serviceHandlers.reconnecting = function (retry) {
console.log("reconnecting...");
return false;
}
in your example, shouldn't it be setInterval ?
gave up on Poloniex because there orderbook feed doesn't include any data. Only the ticker feed works.
it should, yes, sorry.
If you're having the disconnected event being triggered then my example doesn't apply. My example was for the cases I discovered where it was disconnected but it didn't know about it so it never retried. I assume you're using the latest version?
yea latest version. Is there a debug mode i can enable to give more verbose reason behind the aborted connection ? The connection aborted message doesn't seem to be from this library.. i suppose it's from signalR.
The library does very little in the middle. You're basically attached directly to signalR and the library just provides a couple of wrapper commands to make it simpler for you to get connected. You could try look at the data sent to the disconnect function.
bittrex_ws.serviceHandlers.disconnected = function () {
console.log(arguments);
}
I will setup my own test and see if I can replicate it.
I have noticed this as well, seems to run fine for some time, for me usually some hours or 1-2 days, and then it just disconnects without trying to reconnect. Strange thing is, it actually does reconnect most of the time, but sometimes it just stops. Is there a way to manually reset the websocket connection of the api wrapper? I know it works for the base client as dparlevliet pointed out, could someone show how to reset the client of the wrapper?
Alright never mind, just using the listen function again seems to work. In case anyone is interested on how to determine if the client needs to reconnect, my application compares the nounce to the last nounce 15 seconds ago. If it didn't change, my application reconnects.
I got same issue. It seems, web socket was disconnected. in console.log there is 'connection aborted'. so I wrote this code
websocketsclient.serviceHandlers.reconnecting = function (retry) {
console.log('reconnecting');
return false;
}
but it is not working still. How can I reconnect automatically when connection was aborted? who can help me? Thanks in advance
This should do it:
bittrexSocket.serviceHandlers.disconnected = (websocket) => {
console.log("bittrex disconnected, reconnecting immediately");
setImmediate(() => {
bittrexSocket.start();
});
}
Is there any solution yet? i tried @cluttered-code but that just crash my code, and in my IDE shows errors.
@gerardo15 are you using es2015(es6)?
@gerardo15 Try the older format if you aren't using es2015.
es2015 (es6)
const bittrex = require('node.bittrex.api');
const bittrexSocket = bittrex.websockets.listen((data) => {
// Do Something
});
// Reconnect when disconnected
bittrexSocket.serviceHandlers.disconnected = (websocket) => {
console.log("bittrex disconnected");
setImmediate(() => {
bittrexSocket.start();
});
};
es5
var bittrex = require('node.bittrex.api');
var bittrexSocket = bittrex.websockets.listen(function (data) {
// Do Something
});
// Reconnect when disconnected
bittrexSocket.serviceHandlers.disconnected = function (websocket) {
console.log("bittrex disconnected");
setImmediate(function () {
bittrexSocket.start();
});
};