-
Notifications
You must be signed in to change notification settings - Fork 167
Streaming API Disconnects after period of time #131
Comments
Others have reported this but I haven't been able to reproduce in the past. There isn't a config in nforce to retry or reconnect but that is really the responsibility of the faye package under the covers. If you want to fork this and try messing with the faye version and/or configuration, I'd be open to a PR if you got it fixed. |
FYI.... I'm seeing the same thing. |
@Kampe - Have you tried setting the timeout when calling |
This is logged by adding an extension to the FayeClient:
where str is _org.stream(); This is with autoRefresh set to true as well. No notification has been sent up to the client in terms of |
|
Has anyone tried upgrading Faye? Perhaps it's a bug in the packaged version. |
Currently 1.2.3 is running in my app, with a current release of 1.2.4 available. It does not seem to address this kind of bug. My guess at this point, is that it randomly takes too long to respond to the reconnect request and the server says 'Go Away (disconnect).' I have some extensive logging that is added in to try and validate this theory. Of course, the issue isn't easily reproducible, so it is a matter of time. |
this is how i intercepted the disconnect event and pass it up to our implementation. It's not an ideal solution, I think this is actually an issue with Faye not properly sending the disconnect event up. const Logger = {
incoming: function(message, callback) {
console.log(`FAYE - incoming - ${new Date()} - ${JSON.stringify(message)}`)
if ( message.channel === '/meta/disconnect' ) {
errorHandler('disconnected');
}
callback(message);
},
outgoing: function(message, callback) {
console.log(`FAYE - outgoing - ${new Date()} - ${JSON.stringify(message)}`)
callback(message);
}
};
str.client._fayeClient.addExtension(Logger); My errorHandler right now does a reconnect to salesforce + streaming |
@akutta Great work here. This is really appreciated. Could I see the implementation of the errorhandler? I'm assuming that this is what you're using to force a reconnect. I'm willing to put it into nforce as a workaround. We'd just need to strip out the console logs and build it into the stream method. |
My error handler just logs in again (probably unnecessary) and then starts a new streaming connection: var str = this._org.stream({
topic: topic,
oauth: oauth
}); I feel like this should just be propagated up as a 'disconnect' event from the stream so whoever is integrating with nforce can decide the appropriate action. str.on('disconnect', () => { console.log('disconnected from stream'); }) Maybe have a helper function on the stream object that can do the reconnect. |
One thing to ask...have you tried setting different timeout and retry settings in the client? It's possible that there are defaults set by Faye, but the nforce options hash is sending in undefineds and blowing over the internal defaults. Here is where that could be happening: https://github.com/kevinohara80/nforce/blob/master/lib/fdcstream.js#L47 |
I havn't changed the defaults, but I saw that the Faye client defaults were still setup properly while debugging in other portions of the client. |
@kevinohara80 I am also facing the same issue as above . I have subscribed to platform events and for some few hours I am able to receive events but as soon as my token expires I don't receive any event . If I refresh my token and then make new connection and with that connection if I subscribe I will receive the event for new connection and my old one died . So my question is does nforce auto refreshes the access token for platform events. On more observation : Below is my implementation :
For subscribing to platform events :
|
@kevinohara80
|
@kevinohara80 We tried with Faye client version 1.2.4, but still end up the client being disconnected after sometime. |
@kevinohara80 there is an issue raised in faye client repo faye/faye#492 but they suggest since server is responding with reconnect: none they do not attempt again. However I have posted that in such scenarios do they send a transport:down event which we are handling as disconnect. So that any further code on this could be handled appropriately. |
I think I may have a solution in the works for this. It seems as if the reason for the disconnects is oauth access token expirations. I'm going to play with an |
I have tried implementing that auto refresh feature but I had to disable it. Sometimes Faye Client keeps a connection open and for some reason, salesforce kept that open too and I ended up with several active subscribers. The best solution I found was to close the process and start it with pm2 and autorestart. |
@kevinohara80 Just curious to know if the version 2.0 is coming soon? |
Not sure if this is a SF issue itself, but the streaming API seems to lose connection every few hours or so, is there a config to circumvent this and set the connection to keep-alive?
The text was updated successfully, but these errors were encountered: