Resolve trade offers being stuck for too long when ASF API connection is down

This commit is contained in:
Łukasz Domeradzki
2024-03-31 23:30:54 +02:00
parent 79fb392a9a
commit 756a31310f
2 changed files with 11 additions and 2 deletions

View File

@@ -184,7 +184,13 @@ internal static class ArchiNet {
Uri request = new(URL, "/Api/BadBots");
ObjectResponse<GenericResponse<ImmutableHashSet<ulong>>>? response = await ASF.WebBrowser.UrlGetToJsonObject<GenericResponse<ImmutableHashSet<ulong>>>(request, cancellationToken: cancellationToken).ConfigureAwait(false);
ObjectResponse<GenericResponse<ImmutableHashSet<ulong>>>? response = null;
try {
response = await ASF.WebBrowser.UrlGetToJsonObject<GenericResponse<ImmutableHashSet<ulong>>>(request, cancellationToken: cancellationToken).ConfigureAwait(false);
} catch (OperationCanceledException e) {
ASF.ArchiLogger.LogGenericDebuggingException(e);
}
if (response?.Content?.Result == null) {
return (false, ASF.GlobalDatabase.CachedBadBots);

View File

@@ -396,7 +396,10 @@ public sealed class Trading : IDisposable {
// Deny trades from bad steamIDs if user wishes to do so
if (ASF.GlobalConfig?.FilterBadBots ?? GlobalConfig.DefaultFilterBadBots) {
bool? isBadBot = await ArchiNet.IsBadBot(tradeOffer.OtherSteamID64).ConfigureAwait(false);
// Allow no longer than 10 seconds timeout for BadBot call, as we don't want to hold the trade offer for too long
using CancellationTokenSource cts = new(TimeSpan.FromSeconds(10));
bool? isBadBot = await ArchiNet.IsBadBot(tradeOffer.OtherSteamID64, cts.Token).ConfigureAwait(false);
if (isBadBot == true) {
Bot.ArchiLogger.LogGenericDebug(string.Format(CultureInfo.CurrentCulture, Strings.BotTradeOfferResult, tradeOffer.TradeOfferID, ParseTradeResult.EResult.Blacklisted, $"{nameof(tradeOffer.OtherSteamID64)} {tradeOffer.OtherSteamID64}"));