kdcllc / CometD.NetCore.Salesforce

CometD Salesforce Implementation.
MIT License
45 stars 24 forks source link

Allow injecting a strategy for handling invalid replay Ids #25

Closed cternes closed 3 years ago

cternes commented 3 years ago

Maybe this goes a bit too far of what you want to handle in your library, but some kind of callback is needed for the ResilientStreamingClient.

This implementation handles the occurrence of invalid replay Id error from the bus and allows the user to inject a strategy into the client how to handle this error.

ianrandell-sh commented 3 years ago

@cternes what strategy did you implement for your solution? I have tried implementing an unsubscribe followed by a new subscribe (with replayid id of -2), but the unsubscribe ends up with this exception (the strategy is called directly from ErrorExtension_ConnectionError as per the latest code in this repo):

System.Threading.LockRecursionException
Recursive read lock acquisitions not allowed in this mode.
   at System.Threading.ReaderWriterLockSlim.TryEnterReadLockCore(TimeoutTracker timeout)
   at System.Collections.Generic.ThreadSafeList`1.<GetEnumerator>d__18.MoveNext() in C:\projects\cometd-netcore\src\CometD.NetCore\Internal\ThreadSafeList.cs:line 201
   at CometD.NetCore.Common.AbstractClientSession.ExtendSend(IMutableMessage message) in C:\projects\cometd-netcore\src\CometD.NetCore\Common\AbstractClientSession.cs:line 214

Just using a new subscribe (using replay id of -2 and without the unsubscribe) appears to work but does not result in the retained messages being received.

Seems like a re-entrancy issue, i.e. the unsub + new sub needs to happen after the ErrorExtension_ConnectionError has completed (and presumably a lock has been released).

ianrandell-sh commented 3 years ago

further to the above, I tried a different approach which was to capture invalid replay ids and use a timer-activated method in the eventBus to do the un- and re-subscribing. However, I now get a CometD error after re-subscribing (with a new replayId of -2):

400::The channel you requested to subscribe to does not exist {/event/MyEvent__e}

I suspect I need to dig into the code