1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-13 15:03:13 +08:00

Merge pull request #18816 from peppy/avoid-waiting-forever

Ban usage of `ManualResetEventSlim.Wait()` without a timeout value
This commit is contained in:
Dan Balasescu 2022-06-23 17:26:26 +09:00 committed by GitHub
commit 9ed37621a7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 16 additions and 8 deletions

View File

@ -16,3 +16,4 @@ M:Realms.CollectionExtensions.SubscribeForNotifications`1(System.Linq.IQueryable
M:Realms.CollectionExtensions.SubscribeForNotifications`1(System.Collections.Generic.IList{``0},Realms.NotificationCallbackDelegate{``0});Use osu.Game.Database.RealmObjectExtensions.QueryAsyncWithNotifications(IList<T>,NotificationCallbackDelegate<T>) instead. M:Realms.CollectionExtensions.SubscribeForNotifications`1(System.Collections.Generic.IList{``0},Realms.NotificationCallbackDelegate{``0});Use osu.Game.Database.RealmObjectExtensions.QueryAsyncWithNotifications(IList<T>,NotificationCallbackDelegate<T>) instead.
M:System.Threading.Tasks.Task.Wait();Don't use Task.Wait. Use Task.WaitSafely() to ensure we avoid deadlocks. M:System.Threading.Tasks.Task.Wait();Don't use Task.Wait. Use Task.WaitSafely() to ensure we avoid deadlocks.
P:System.Threading.Tasks.Task`1.Result;Don't use Task.Result. Use Task.GetResultSafely() to ensure we avoid deadlocks. P:System.Threading.Tasks.Task`1.Result;Don't use Task.Result. Use Task.GetResultSafely() to ensure we avoid deadlocks.
M:System.Threading.ManualResetEventSlim.Wait();Specify a timeout to avoid waiting forever.

View File

@ -76,7 +76,7 @@ namespace osu.Game.Benchmarks
} }
}); });
done.Wait(); done.Wait(60000);
} }
[Benchmark] [Benchmark]
@ -115,7 +115,7 @@ namespace osu.Game.Benchmarks
} }
}); });
done.Wait(); done.Wait(60000);
} }
[Benchmark] [Benchmark]

View File

@ -79,11 +79,11 @@ namespace osu.Game.Tests.Database
{ {
hasThreadedUsage.Set(); hasThreadedUsage.Set();
stopThreadedUsage.Wait(); stopThreadedUsage.Wait(60000);
}); });
}, TaskCreationOptions.LongRunning | TaskCreationOptions.HideScheduler); }, TaskCreationOptions.LongRunning | TaskCreationOptions.HideScheduler);
hasThreadedUsage.Wait(); hasThreadedUsage.Wait(60000);
Assert.Throws<TimeoutException>(() => Assert.Throws<TimeoutException>(() =>
{ {

View File

@ -46,7 +46,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
{ {
Task.Run(() => Task.Run(() =>
{ {
allowResponseCallback.Wait(); allowResponseCallback.Wait(10000);
allowResponseCallback.Reset(); allowResponseCallback.Reset();
Schedule(() => d?.Invoke("Incorrect password")); Schedule(() => d?.Invoke("Incorrect password"));
}); });

View File

@ -209,6 +209,10 @@ namespace osu.Game.Database
public void SetMigrationCompletion() => migrationComplete.Set(); public void SetMigrationCompletion() => migrationComplete.Set();
public void WaitForMigrationCompletion() => migrationComplete.Wait(); public void WaitForMigrationCompletion()
{
if (!migrationComplete.Wait(300000))
throw new TimeoutException("Migration took too long (likely stuck).");
}
} }
} }

View File

@ -103,7 +103,9 @@ namespace osu.Game.Graphics
framesWaitedEvent.Set(); framesWaitedEvent.Set();
}, 10, true); }, 10, true);
framesWaitedEvent.Wait(); if (!framesWaitedEvent.Wait(1000))
throw new TimeoutException("Screenshot data did not arrive in a timely fashion");
waitDelegate.Cancel(); waitDelegate.Cancel();
} }
} }

View File

@ -451,7 +451,8 @@ namespace osu.Game
readyToRun.Set(); readyToRun.Set();
}, false); }, false);
readyToRun.Wait(); if (!readyToRun.Wait(30000))
throw new TimeoutException("Attempting to block for migration took too long.");
bool? cleanupSucceded = (Storage as OsuStorage)?.Migrate(Host.GetStorage(path)); bool? cleanupSucceded = (Storage as OsuStorage)?.Migrate(Host.GetStorage(path));