Skip to content

Commit

Permalink
Removed owned emotes request timeout since when on heavy load users m…
Browse files Browse the repository at this point in the history
…ight encounter a Timeout and we are not even handling the timeout correctly with retry mechanics
  • Loading branch information
Kinerius committed Nov 17, 2023
1 parent 495e2c5 commit 74a9a71
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System.Collections.Generic;
using System.Threading;
using Cysharp.Threading.Tasks;
using DCL;
using DCL.Emotes;
Expand All @@ -9,6 +7,8 @@
using DCLServices.Lambdas;
using DCLServices.WearablesCatalogService;
using System;
using System.Collections.Generic;
using System.Threading;
using UnityEngine;

public class LambdasEmotesCatalogService : IEmotesCatalogService
Expand Down Expand Up @@ -160,23 +160,14 @@ public Promise<IReadOnlyList<WearableItem>> RequestOwnedEmotes(string userId)

public async UniTask<IReadOnlyList<WearableItem>> RequestOwnedEmotesAsync(string userId, CancellationToken ct = default)
{
const int TIMEOUT = 60;
CancellationTokenSource timeoutCTS = new CancellationTokenSource();
var timeout = timeoutCTS.CancelAfterSlim(TimeSpan.FromSeconds(TIMEOUT));
var promise = RequestOwnedEmotes(userId);

try
{
ct.ThrowIfCancellationRequested();
var linkedCt = CancellationTokenSource.CreateLinkedTokenSource(ct, timeoutCTS.Token);
await promise.WithCancellation(linkedCt.Token);
await promise.WithCancellation(ct);
}
catch (OperationCanceledException e) { return null; }
finally
{
timeout?.Dispose();
timeoutCTS?.Dispose();
}

return promise.value;
}
Expand Down Expand Up @@ -307,9 +298,10 @@ public async UniTask<IReadOnlyList<WearableItem>> RequestEmotesAsync(IList<strin
try
{
var tasks = ids.Select(x => RequestEmoteAsync(x, ct));
return await UniTask.WhenAll(tasks).AttachExternalCancellation(ct);
WearableItem[] result = await UniTask.WhenAll(tasks).AttachExternalCancellation(ct);
return result;
}
catch (OperationCanceledException e) { return null; }
catch (OperationCanceledException) { return null; }
}

public void ForgetEmote(string id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;

namespace DCLServices.EmotesCatalog
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,18 +121,14 @@ async UniTaskVoid LoadEmotesAsync(CancellationToken ct = default)
}

allEmotes = consolidatedEmotes.Values.ToList();
UpdateEmotes();

try
{
await FetchCustomEmoteItems(allEmotes, ct);
await FetchCustomEmoteCollections(allEmotes, ct);
UpdateEmotes();
}
catch (Exception e) when (e is not OperationCanceledException)
{
Debug.LogException(e);
}
catch (Exception e) when (e is not OperationCanceledException) { Debug.LogException(e); }
finally { UpdateEmotes(); }

void UpdateEmotes()
{
Expand Down

0 comments on commit 74a9a71

Please sign in to comment.