Skip to content
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

Ban usage of ManualResetEventSlim.Wait() without a timeout value #18816

Merged
merged 3 commits into from
Jun 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CodeAnalysis/BannedSymbols.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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: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.
M:System.Threading.ManualResetEventSlim.Wait();Specify a timeout to avoid waiting forever.
4 changes: 2 additions & 2 deletions osu.Game.Benchmarks/BenchmarkRealmReads.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public void BenchmarkDirectPropertyReadUpdateThread()
}
});

done.Wait();
done.Wait(60000);
}

[Benchmark]
Expand Down Expand Up @@ -115,7 +115,7 @@ public void BenchmarkRealmLivePropertyReadUpdateThread()
}
});

done.Wait();
done.Wait(60000);
}

[Benchmark]
Expand Down
4 changes: 2 additions & 2 deletions osu.Game.Tests/Database/GeneralUsageTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@ public void TestBlockOperationsWithContention()
{
hasThreadedUsage.Set();

stopThreadedUsage.Wait();
stopThreadedUsage.Wait(60000);
});
}, TaskCreationOptions.LongRunning | TaskCreationOptions.HideScheduler);

hasThreadedUsage.Wait();
hasThreadedUsage.Wait(60000);

Assert.Throws<TimeoutException>(() =>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ private void load()
{
Task.Run(() =>
{
allowResponseCallback.Wait();
allowResponseCallback.Wait(10000);
allowResponseCallback.Reset();
Schedule(() => d?.Invoke("Incorrect password"));
});
Expand Down
6 changes: 5 additions & 1 deletion osu.Game/Database/DatabaseContextFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,10 @@ public void FlushConnections()

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).");
}
}
}
4 changes: 3 additions & 1 deletion osu.Game/Graphics/ScreenshotManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ public Task TakeScreenshotAsync() => Task.Run(async () =>
framesWaitedEvent.Set();
}, 10, true);

framesWaitedEvent.Wait();
if (!framesWaitedEvent.Wait(1000))
throw new TimeoutException("Screenshot data did not arrive in a timely fashion");

waitDelegate.Cancel();
}
}
Expand Down
3 changes: 2 additions & 1 deletion osu.Game/OsuGameBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,8 @@ public bool Migrate(string path)
readyToRun.Set();
}, 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));

Expand Down