-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Add safeties against exceptions in OnlineLookupCache
#36282
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -8,6 +8,8 @@ | |||||||||||||||
| using System.Threading.Tasks; | ||||||||||||||||
| using osu.Framework.Allocation; | ||||||||||||||||
| using osu.Framework.Extensions; | ||||||||||||||||
| using osu.Framework.Extensions.ExceptionExtensions; | ||||||||||||||||
| using osu.Framework.Logging; | ||||||||||||||||
| using osu.Game.Online.API; | ||||||||||||||||
|
|
||||||||||||||||
| namespace osu.Game.Database | ||||||||||||||||
|
|
@@ -81,7 +83,7 @@ public abstract partial class OnlineLookupCache<TLookup, TValue, TRequest> : Mem | |||||||||||||||
| pendingTasks.Enqueue((id, tcs)); | ||||||||||||||||
|
|
||||||||||||||||
| // Create a request task if there's not already one. | ||||||||||||||||
| if (pendingRequestTask == null) | ||||||||||||||||
| if (pendingRequestTask == null || pendingRequestTask.IsFaulted) | ||||||||||||||||
| createNewTask(); | ||||||||||||||||
|
|
||||||||||||||||
| return tcs.Task; | ||||||||||||||||
|
|
@@ -163,6 +165,14 @@ private void finishPendingTask() | |||||||||||||||
| } | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| private void createNewTask() => pendingRequestTask = Task.Run(performLookup); | ||||||||||||||||
| private void createNewTask() | ||||||||||||||||
| { | ||||||||||||||||
| var nextTask = Task.Run(performLookup); | ||||||||||||||||
| nextTask.ContinueWith(t => | ||||||||||||||||
| { | ||||||||||||||||
| Logger.Error(t.Exception.AsSingular(), $"{nameof(OnlineLookupCache<TLookup, TValue, TRequest>)} lookup request failed!"); | ||||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I'd recommend switching to
Suggested change
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did check on this and they are debounced, also won't be fired in case of an actual network error (LUCKILY, else this would be game over for most users), see: osu/osu.Game/Online/API/APIAccess.cs Lines 371 to 375 in 8bb885a
Felt like something we probably want to fire to sentry, but can alter if you disagree.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe fine then, not sure 🤷 |
||||||||||||||||
| }, TaskContinuationOptions.OnlyOnFaulted); | ||||||||||||||||
| pendingRequestTask = nextTask; | ||||||||||||||||
| } | ||||||||||||||||
| } | ||||||||||||||||
| } | ||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could just clear the pending task in the
OnlyOnFaultedcontinuation that was added anyway for logging purposes instead. No real preference here, maybe slightly nicer.