1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 16:25:32 +08:00
osu-lazer/osu.Game/Screens
Bartłomiej Dach 3c5e9ac9a9
Fix possible double score submission when auto-retrying via perfect mod
Closes https://github.com/ppy/osu/issues/26035.

`submitOnFailOrQuit()`, as the name suggests, can be called both when
the player has failed, or when the player screen is being exited from.
Notably, when perfect mod with auto-retry is active, the two happen
almost simultaneously.

This double call exposes a data race in `submitScore()` concerning the
handling of `scoreSubmissionSource`. The race could be experimentally
confirmed by applying the following patch:

diff --git a/osu.Game/Screens/Play/SubmittingPlayer.cs b/osu.Game/Screens/Play/SubmittingPlayer.cs
index 83adf1f960..76dd29bbdb 100644
--- a/osu.Game/Screens/Play/SubmittingPlayer.cs
+++ b/osu.Game/Screens/Play/SubmittingPlayer.cs
@@ -228,6 +228,7 @@ private Task submitScore(Score score)
                 return Task.CompletedTask;
             }

+            Logger.Log($"{nameof(scoreSubmissionSource)} is {(scoreSubmissionSource == null ? "null" : "not null")}");
             if (scoreSubmissionSource != null)
                 return scoreSubmissionSource.Task;

@@ -237,6 +238,7 @@ private Task submitScore(Score score)

             Logger.Log($"Beginning score submission (token:{token.Value})...");

+            Logger.Log($"creating new {nameof(scoreSubmissionSource)}");
             scoreSubmissionSource = new TaskCompletionSource<bool>();
             var request = CreateSubmissionRequest(score, token.Value);

which would result in the following log output:

	[runtime] 2024-01-02 09:54:13 [verbose]: scoreSubmissionSource is null
	[runtime] 2024-01-02 09:54:13 [verbose]: scoreSubmissionSource is null
	[runtime] 2024-01-02 09:54:13 [verbose]: Beginning score submission (token:36780)...
	[runtime] 2024-01-02 09:54:13 [verbose]: creating new scoreSubmissionSource
	[runtime] 2024-01-02 09:54:13 [verbose]: Beginning score submission (token:36780)...
	[runtime] 2024-01-02 09:54:13 [verbose]: creating new scoreSubmissionSource
	[network] 2024-01-02 09:54:13 [verbose]: Performing request osu.Game.Online.Solo.SubmitSoloScoreRequest
	[network] 2024-01-02 09:54:14 [verbose]: Request to https://dev.ppy.sh/api/v2/beatmaps/869310/solo/scores/36780 successfully completed!
	[network] 2024-01-02 09:54:14 [verbose]: SubmitSoloScoreRequest finished with response size of 639 bytes
	[network] 2024-01-02 09:54:14 [verbose]: Performing request osu.Game.Online.Solo.SubmitSoloScoreRequest
	[runtime] 2024-01-02 09:54:14 [verbose]: Score submission completed! (token:36780 id:20247)
	[network] 2024-01-02 09:54:14 [verbose]: Request to https://dev.ppy.sh/api/v2/beatmaps/869310/solo/scores/36780 successfully completed!
	[network] 2024-01-02 09:54:14 [verbose]: SubmitSoloScoreRequest finished with response size of 639 bytes
	[runtime] 2024-01-02 09:54:14 [error]: An unhandled error has occurred.
	[runtime] 2024-01-02 09:54:14 [error]: System.InvalidOperationException: An attempt was made to transition a task to a final state when it had already completed.
	[runtime] 2024-01-02 09:54:14 [error]: at osu.Game.Screens.Play.SubmittingPlayer.<>c__DisplayClass30_0.<submitScore>b__0(MultiplayerScore s) in /home/dachb/Documents/opensource/osu/osu.Game/Screens/Play/SubmittingPlayer.cs:line 250

The intention of the submission logic was to only ever create one
`scoreSubmissionSource`, and then reuse this one if a redundant
submission request was made. However, because of the temporal proximity
of fail and quit in this particular case, combined with the fact that
the calls to `submitScore()` are taking place on TPL threads, means that
there is a read-write data race on `scoreSubmissionSource`, wherein the
source can be actually created twice.

This leads to two concurrent score submission requests, which, upon
completion, attempt to transition only _the second_
`scoreSubmissionSource` to a final state (this is because the API
success/failure request callbacks capture `this`, i.e. the entire
`SubmittingPlayer` instance, rather than the `scoreSubmissionSource`
reference specifically).

To fix, ensure correct synchronisation on the read-write critical
section, which should prevent the `scoreSubmissionSource` from being
created multiple times.
2024-01-02 10:55:52 +01:00
..
Backgrounds Use alternative method of scheduling storyboard unload 2023-11-16 15:37:53 +09:00
Edit change floor to round 2023-12-30 23:59:47 -06:00
Import Merge branch 'master' into update-framework 2022-11-26 16:19:36 +01:00
Menu Merge branch 'master' of https://github.com/ppy/osu into menu-button-tweaks 2023-12-30 12:58:10 -06:00
OnlinePlay Remove unused class 2023-12-05 12:43:32 +01:00
Play Fix possible double score submission when auto-retrying via perfect mod 2024-01-02 10:55:52 +01:00
Ranking Reorder badges so that SS shows above others 2023-11-29 20:29:52 +09:00
Select Fix song select leaderboard tab ordering not matching stable 2023-12-28 14:13:35 +09:00
Spectate Add visualisation of when a spectated player fails 2023-11-24 14:44:57 +09:00
Utility Calculate unstable rate using rate-adjusted offsets 2023-11-10 19:57:44 -08:00
BackgroundScreen.cs Unload beatmap storyboard background when no longer present 2023-11-09 17:20:11 +03:00
BackgroundScreenStack.cs Use alternative method of scheduling storyboard unload 2023-11-16 15:37:53 +09:00
IHandlePresentBeatmap.cs Automated pass 2023-06-24 01:00:03 +09:00
IHasSubScreenStack.cs Automated pass 2023-06-24 01:00:03 +09:00
IOsuScreen.cs Allow screens to change the ability to interact with the global track 2023-07-25 20:20:53 +09:00
IPerformFromScreenRunner.cs Automated #nullable processing 2022-06-17 16:37:17 +09:00
Loader.cs Remove disclaimer screen completely 2023-12-28 17:21:29 +09:00
OsuScreen.cs Fix various other inspections 2023-10-17 17:48:51 +09:00
OsuScreenDependencies.cs Automated #nullable processing 2022-06-17 16:37:17 +09:00
OsuScreenStack.cs Manual fixes to reduce warnings to zero 2023-06-24 01:52:53 +09:00
ScorePresentType.cs Remove redundant nullable suppression directives 2023-06-07 08:20:41 +03:00
ScreenWhiteBox.cs Partial everything 2022-11-27 00:00:27 +09:00
StartupScreen.cs Automated pass 2023-06-24 01:00:03 +09:00