Skip to content

Commit 050c10c

Browse files
authored
Ensure all invocations of spectator server hub methods have their errors observed (#35488)
Fell out when attempting ppy/osu-server-spectator#346. Functionally, if a true non-`HubException` is produced via an invocation of a spectator server hub method, this doesn't really do much - the error will still log as 'unobserved' due to the default handler, it will still show up on sentry, etc. The only difference is that it'll get handled via the continuation installed in `FireAndForget()` rather than the `TaskScheduler.UnobservedTaskException` event. The only real case where this is relevant is when the server throws `HubException`s, which will now instead bubble up to a more human-readable form. Which is relevant to the aforementioned PR because that one makes any hub method potentially throw a `HubException` if the client version is too old. Obviously this does nothing for the existing old clients.
1 parent b4fd7ec commit 050c10c

File tree

8 files changed

+16
-15
lines changed

8 files changed

+16
-15
lines changed

osu.Game/Online/Metadata/OnlineMetadataClient.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,13 @@ protected override void LoadComplete()
8989
userStatus.BindValueChanged(status =>
9090
{
9191
if (localUser.Value is not GuestUser)
92-
UpdateStatus(status.NewValue);
92+
UpdateStatus(status.NewValue).FireAndForget();
9393
}, true);
9494

9595
userActivity.BindValueChanged(activity =>
9696
{
9797
if (localUser.Value is not GuestUser)
98-
UpdateActivity(activity.NewValue);
98+
UpdateActivity(activity.NewValue).FireAndForget();
9999
}, true);
100100
}
101101

@@ -121,8 +121,8 @@ private void isConnectedChanged(ValueChangedEvent<bool> connected)
121121

122122
if (localUser.Value is not GuestUser)
123123
{
124-
UpdateActivity(userActivity.Value);
125-
UpdateStatus(userStatus.Value);
124+
UpdateActivity(userActivity.Value).FireAndForget();
125+
UpdateStatus(userStatus.Value).FireAndForget();
126126
}
127127

128128
if (lastQueueId.Value >= 0)

osu.Game/Online/Multiplayer/MultiplayerClient.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ private void load()
201201
if (!connected.NewValue)
202202
{
203203
if (Room != null)
204-
LeaveRoom();
204+
LeaveRoom().FireAndForget();
205205

206206
MatchmakingQueueLeft?.Invoke();
207207
}
@@ -560,7 +560,7 @@ Task IMultiplayerClient.UserKicked(MultiplayerRoomUser user)
560560
return;
561561

562562
if (user.Equals(LocalUser))
563-
LeaveRoom();
563+
LeaveRoom().FireAndForget();
564564

565565
handleUserLeft(user, UserKicked);
566566
});

osu.Game/Online/Spectator/SpectatorClient.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
using osu.Framework.Logging;
1515
using osu.Game.Beatmaps;
1616
using osu.Game.Online.API;
17+
using osu.Game.Online.Multiplayer;
1718
using osu.Game.Replays.Legacy;
1819
using osu.Game.Rulesets.Replays;
1920
using osu.Game.Rulesets.Replays.Types;
@@ -203,7 +204,7 @@ Task ISpectatorClient.UserEndedWatching(int userId)
203204

204205
Task IStatefulUserHubClient.DisconnectRequested()
205206
{
206-
Schedule(() => DisconnectInternal());
207+
Schedule(() => DisconnectInternal().FireAndForget());
207208
return Task.CompletedTask;
208209
}
209210

@@ -290,7 +291,7 @@ public void EndPlaying(GameplayState state)
290291
else
291292
currentState.State = SpectatedUserState.Quit;
292293

293-
EndPlayingInternal(currentState);
294+
EndPlayingInternal(currentState).FireAndForget();
294295
});
295296
}
296297

@@ -304,7 +305,7 @@ public virtual void WatchUser(int userId)
304305
return;
305306
}
306307

307-
WatchUserInternal(userId);
308+
WatchUserInternal(userId).FireAndForget();
308309
}
309310

310311
public void StopWatchingUser(int userId)
@@ -321,7 +322,7 @@ public void StopWatchingUser(int userId)
321322

322323
watchedUsersRefCounts.Remove(userId);
323324
watchedUserStates.Remove(userId);
324-
StopWatchingUserInternal(userId);
325+
StopWatchingUserInternal(userId).FireAndForget();
325326
});
326327
}
327328

osu.Game/Screens/OnlinePlay/Matchmaking/Match/ScreenMatchmaking.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ public override void OnResuming(ScreenTransitionEvent e)
392392
return;
393393
}
394394

395-
client.ChangeState(MultiplayerUserState.Idle);
395+
client.ChangeState(MultiplayerUserState.Idle).FireAndForget();
396396
}
397397

398398
/// <summary>

osu.Game/Screens/OnlinePlay/Multiplayer/Multiplayer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ private void transitionFromResults()
8787
Debug.Assert(client.LocalUser != null);
8888

8989
if (client.LocalUser.State == MultiplayerUserState.Results)
90-
client.ChangeState(MultiplayerUserState.Idle);
90+
client.ChangeState(MultiplayerUserState.Idle).FireAndForget();
9191
}
9292

9393
protected override string ScreenTitle => "Multiplayer";

osu.Game/Screens/OnlinePlay/Multiplayer/MultiplayerMatchSubScreen.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@ private void onBeatmapAvailabilityChanged(ValueChangedEvent<BeatmapAvailability>
618618
updateGameplayState();
619619

620620
if (client.LocalUser.State == MultiplayerUserState.Ready)
621-
client.ChangeState(MultiplayerUserState.Idle);
621+
client.ChangeState(MultiplayerUserState.Idle).FireAndForget();
622622
break;
623623
}
624624
}

osu.Game/Screens/OnlinePlay/Multiplayer/MultiplayerPlayer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ protected override void StartGameplay()
161161
if (client.LocalUser?.State == MultiplayerUserState.Loaded)
162162
{
163163
loadingDisplay.Show();
164-
client.ChangeState(MultiplayerUserState.ReadyForGameplay);
164+
client.ChangeState(MultiplayerUserState.ReadyForGameplay).FireAndForget();
165165
}
166166

167167
// This will pause the clock, pending the gameplay started callback from the server.

osu.Game/Screens/OnlinePlay/Multiplayer/Spectate/MultiSpectatorScreen.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ public override bool OnBackButton()
296296
// On a manual exit, set the player back to idle unless gameplay has finished.
297297
// Of note, this doesn't cover exiting using alt-f4 or menu home option.
298298
if (multiplayerClient.Room.State != MultiplayerRoomState.Open)
299-
multiplayerClient.ChangeState(MultiplayerUserState.Idle);
299+
multiplayerClient.ChangeState(MultiplayerUserState.Idle).FireAndForget();
300300

301301
return base.OnBackButton();
302302
}

0 commit comments

Comments
 (0)