From 56a6e10189f613f0a4ac562e6e3827664b512d0c Mon Sep 17 00:00:00 2001 From: JustArchi Date: Wed, 22 Jun 2016 02:02:43 +0200 Subject: [PATCH] Correct retry logic of API requests Timeout will result in WebClient does not support concurrent I/O operations for concurrent calls Therefore, retry with new WebClient instead --- ArchiSteamFarm/ArchiWebHandler.cs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/ArchiSteamFarm/ArchiWebHandler.cs b/ArchiSteamFarm/ArchiWebHandler.cs index dd76ab09f..615f280b6 100644 --- a/ArchiSteamFarm/ArchiWebHandler.cs +++ b/ArchiSteamFarm/ArchiWebHandler.cs @@ -370,10 +370,10 @@ namespace ArchiSteamFarm { } KeyValue response = null; - using (dynamic iPlayerService = WebAPI.GetInterface("IPlayerService", Bot.BotConfig.SteamApiKey)) { - iPlayerService.Timeout = Timeout; + for (byte i = 0; (i < WebBrowser.MaxRetries) && (response == null); i++) { + using (dynamic iPlayerService = WebAPI.GetInterface("IPlayerService", Bot.BotConfig.SteamApiKey)) { + iPlayerService.Timeout = Timeout; - for (byte i = 0; (i < WebBrowser.MaxRetries) && (response == null); i++) { try { response = iPlayerService.GetOwnedGames( steamid: steamID, @@ -407,10 +407,10 @@ namespace ArchiSteamFarm { internal uint GetServerTime() { KeyValue response = null; - using (dynamic iTwoFactorService = WebAPI.GetInterface("ITwoFactorService")) { - iTwoFactorService.Timeout = Timeout; + for (byte i = 0; (i < WebBrowser.MaxRetries) && (response == null); i++) { + using (dynamic iTwoFactorService = WebAPI.GetInterface("ITwoFactorService")) { + iTwoFactorService.Timeout = Timeout; - for (byte i = 0; (i < WebBrowser.MaxRetries) && (response == null); i++) { try { response = iTwoFactorService.QueryTime( method: WebRequestMethods.Http.Post, @@ -488,10 +488,10 @@ namespace ArchiSteamFarm { } KeyValue response = null; - using (dynamic iEconService = WebAPI.GetInterface("IEconService", Bot.BotConfig.SteamApiKey)) { - iEconService.Timeout = Timeout; + for (byte i = 0; (i < WebBrowser.MaxRetries) && (response == null); i++) { + using (dynamic iEconService = WebAPI.GetInterface("IEconService", Bot.BotConfig.SteamApiKey)) { + iEconService.Timeout = Timeout; - for (byte i = 0; (i < WebBrowser.MaxRetries) && (response == null); i++) { try { response = iEconService.GetTradeOffers( get_received_offers: 1, @@ -625,10 +625,10 @@ namespace ArchiSteamFarm { } KeyValue response = null; - using (dynamic iEconService = WebAPI.GetInterface("IEconService", Bot.BotConfig.SteamApiKey)) { - iEconService.Timeout = Timeout; + for (byte i = 0; (i < WebBrowser.MaxRetries) && (response == null); i++) { + using (dynamic iEconService = WebAPI.GetInterface("IEconService", Bot.BotConfig.SteamApiKey)) { + iEconService.Timeout = Timeout; - for (byte i = 0; (i < WebBrowser.MaxRetries) && (response == null); i++) { try { response = iEconService.DeclineTradeOffer( tradeofferid: tradeID.ToString(),