maxisoft / ASFFreeGames

Collect free steam games while asf is running
GNU Affero General Public License v3.0
121 stars 2 forks source link

Crash if reddit request fails #72

Closed supermopf closed 1 month ago

supermopf commented 1 month ago

Describe the bug If the reddit request failes, ASF crashes. In my scenario, this is probably caused by the ip pool of the server or a rate limit.

To Reproduce Steps to reproduce the behavior:

  1. Get blocked by reddit (HTTP 403 Blocked/Forbidden)
  2. Run the plugin

Expected behavior Error should be handled and dont crash.

Screenshots

[22:53:29] INFO Zulu > Init() Success!
[22:53:29] INFO Zulu > IsAnythingToFarm() Checking first badge page...
[22:53:30] INFO Zulu > StartFarming() We don't have anything to farm on this account!
[22:53:41] DEBUG ASF > InternalRequest() Forbidden <- GET https://www.reddit.com/user/ASFinfo.json?sort=new
[22:53:41] WARN ASF > UrlGetToStream() Request failed after 5 attempts!
[22:53:41] DEBUG ASF > UrlGetToStream() Request failing: https://www.reddit.com/user/ASFinfo.json?sort=new
[22:53:41] DEBUG ASF > InternalRequest() Forbidden <- GET https://www.reddit.com/user/ASFinfo.json?sort=new
[22:53:41] WARN ASF > UrlGetToStream() Request failed after 5 attempts!
[22:53:41] DEBUG ASF > UrlGetToStream() Request failing: https://www.reddit.com/user/ASFinfo.json?sort=new
[22:53:41] DEBUG ASF > InternalRequest() Forbidden <- GET https://www.reddit.com/user/ASFinfo.json?sort=new
[22:53:41] WARN ASF > UrlGetToStream() Request failed after 5 attempts!
[22:53:41] DEBUG ASF > UrlGetToStream() Request failing: https://www.reddit.com/user/ASFinfo.json?sort=new
[22:53:42] DEBUG ASF > InternalRequest() Forbidden <- GET https://www.reddit.com/user/ASFinfo.json?sort=new
[22:53:42] WARN ASF > UrlGetToStream() Request failed after 5 attempts!
[22:53:42] DEBUG ASF > UrlGetToStream() Request failing: https://www.reddit.com/user/ASFinfo.json?sort=new
[22:53:44] DEBUG ASF > InternalRequest() Forbidden <- GET https://www.reddit.com/user/ASFinfo.json?sort=new
[22:53:44] WARN ASF > UrlGetToStream() Request failed after 5 attempts!
[22:53:44] DEBUG ASF > UrlGetToStream() Request failing: https://www.reddit.com/user/ASFinfo.json?sort=new
[22:53:44] FATAL ASF > OnUnhandledException() Maxisoft.ASF.Reddit.RedditServerException: Reddit server error: content is null at Maxisoft.ASF.Reddit.RedditHelper.GetPayload(WebBrowser webBrowser, CancellationToken cancellationToken, UInt32 retry) at Maxisoft.ASF.Reddit.RedditHelper.GetPayload(WebBrowser webBrowser, CancellationToken cancellationToken, UInt32 retry) at Maxisoft.ASF.Reddit.RedditHelper.GetGames(CancellationToken cancellationToken) at ASFFreeGames.Commands.FreeGamesCommand.CollectGames(IEnumerable`1 bots, ECollectGameRequestSource requestSource, CancellationToken cancellationToken) at ASFFreeGames.Commands.FreeGamesCommand.HandleInternalCollectCommand(Bot bot, String[] args, CancellationToken cancellationToken) at ASFFreeGames.Commands.FreeGamesCommand.Execute(Bot bot, String message, String[] args, UInt64 steamID, CancellationToken cancellationToken) at ASFFreeGames.Commands.CommandDispatcher.Execute(Bot bot, String message, String[] args, UInt64 steamID, CancellationToken cancellationToken) at Maxisoft.ASF.ASFFreeGamesPlugin.OnBotCommand(Bot bot, EAccess access, String message, String[] args, UInt64 steamID) at Maxisoft.ASF.ASFFreeGamesPlugin.CollectGamesOnClock(Object source) at System.Threading.Tasks.Task.<>c.<ThrowAsync>b__128_1(Object state) at System.Threading.QueueUserWorkItemCallback.<>c.<.cctor>b__6_0(QueueUserWorkItemCallback quwi) at System.Threading.ExecutionContext.RunForThreadPoolUnsafe[TState](ExecutionContext, Action`1, TState& ) at System.Threading.QueueUserWorkItemCallback.Execute() at System.Threading.ThreadPoolWorkQueue.Dispatch() at System.Threading.PortableThreadPool.WorkerThread.WorkerThreadStart() at System.Threading.Thread.StartCallback()
[22:53:44] ERROR ASF > Exit() Exiting with 1 error code!
[22:53:44] INFO Microsoft.Hosting.Lifetime > Application is shutting down...

ASF:

maxisoft commented 1 month ago

The issue with the plugin crashing on Reddit request failures has been addressed with the latest commit. Exception handling has been improved to catch and log errors without stopping the plugin's and asf execution. This should resolve the crash issue described in #72.

The changes will be available in the next release. Thank you for your patience and for reporting this issue!