Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoids retrying on 403s #123

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/Api/PubnubApi/EndPoint/PubSub/SubscribeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -670,10 +670,12 @@ private void MultiChannelSubscribeRequest<T>(PNOperationType type, string[] chan

// Wait for message
string json = "";
PNStatus pNStatus = null;
UrlProcessRequest<T>(request, pubnubRequestState, false).ContinueWith(r =>
{
pNStatus = r.Result.Item2;
json = r.Result.Item1;
}, TaskContinuationOptions.ExecuteSynchronously).Wait();
}, TaskContinuationOptions.ExecuteSynchronously).Wait(); //TODO: Maybe it's time to port this to full async/await syntax? Just saying.
if (!string.IsNullOrEmpty(json))
{
string subscribedChannels = (MultiChannelSubscribe.ContainsKey(PubnubInstance.InstanceId) && MultiChannelSubscribe[PubnubInstance.InstanceId].Count > 0) ? MultiChannelSubscribe[PubnubInstance.InstanceId].Keys.OrderBy(x=>x).Aggregate((x, y) => x + "," + y) : "";
Expand Down Expand Up @@ -728,7 +730,7 @@ private void MultiChannelSubscribeRequest<T>(PNOperationType type, string[] chan
}

}
else
else if (pNStatus == null || pNStatus.Category != PNStatusCategory.PNAccessDeniedCategory) //so we do not retry if you get a 403. Only if there's no connection, i.e. the pnStatus object is null.
{
if (multiplexExceptionTimer != null)
{
Expand All @@ -737,9 +739,16 @@ private void MultiChannelSubscribeRequest<T>(PNOperationType type, string[] chan
ConnectionErrors++;
UpdatePubnubNetworkTcpCheckIntervalInSeconds();
multiplexExceptionTimer = new Timer(new TimerCallback(MultiplexExceptionHandlerTimerCallback<T>), pubnubRequestState,
(-1 == PubnubNetworkTcpCheckIntervalInSeconds) ? Timeout.Infinite : PubnubNetworkTcpCheckIntervalInSeconds * 1000,
(-1 == PubnubNetworkTcpCheckIntervalInSeconds) ? Timeout.Infinite : PubnubNetworkTcpCheckIntervalInSeconds * 1000,
Timeout.Infinite);
}
else
{
//TODO: we have a situation that we should probably let the user know about so that the client code can deal with it, or let the user know.
//List<object> result = ProcessJsonResponse<T>(pubnubRequestState, json);
//ProcessResponseCallbacks(result, pubnubRequestState);
Announce(pNStatus);
}
}
catch (Exception ex)
{
Expand Down