faye / faye

Simple pub/sub messaging for the web
http://faye.jcoglan.com
Other
4.39k stars 365 forks source link

Queries on _handleAdvice function #535

Open dtto86 opened 2 years ago

dtto86 commented 2 years ago

Hi

On reception of {"advice":{"interval":0,"reconnect":"handshake"},"channel":"/meta/connect","id":"5p","error":"403::Unknown client","successful":false} error from Salesforce.com, client calls _handleAdvice function https://github.com/faye/faye/blob/master/src/protocol/client.js#L353 and creates new client and new subscription on a topic with replayId.

My questions are

  1. Why faye client is calling connect function on occurrence of "advice":{"interval":0,"reconnect":"handshake"} in _handleAdvice? Is it as per the design?
  2. Why faye client is creating new subscription with older replayId. Please note here, we are using nforce npm package. Last processed event: {"data":{"schema":"0c5uHJiCMwqzxeBHzibiag","payload":{"CreatedById":"0055g000004VXJnAAO","CreatedDate":"2022-03-24T15:34:18.123Z","abcc":"amrt-run"},"event":{"replayId":4817372}},"channel":"/event/PlatformEvente"} Subscription after 403::Unknown client error: {"channel":"/meta/subscribe","clientId":"6qnbw6zn8dabkws28tn7mawylg9","subscription":"/event/PlatformEvente","id":"2x","ext":{"replay":{"/event/MyPSLe":4817264}}}
  3. Can we override the _handleAdvice so that underlying faye client should not call it's in-built _handleAdvice but override function called in our code?
jcoglan commented 2 years ago

The intended behaviour of the Faye client when receiving a "reconnect": "handshake" message like this is that it should forget its current clientId, and perform a fresh handshake to get a new clientId from the server. Once it has done that successfully, it re-registers any subscriptions to channels it was subscribed to before its previous session expired, so that you don't have to handle this reconnection failure yourself.

I am not able to answer questions about the Salesforce API. Overriding _handleAdvice() is not recommended as it is a private method, and changing its behaviour will probably break the client in some way.