Skip to content

Commit 94959ba

Browse files
authored
Merge pull request #274 from smoogipoo/remove-interop-retry
Retry interop calls only for 5XX responses
2 parents b51fc1f + f5a4158 commit 94959ba

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

osu.Server.Spectator/Services/SharedInterop.cs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System;
55
using System.Linq;
6+
using System.Net;
67
using System.Net.Http;
78
using System.Net.Http.Headers;
89
using System.Security.Cryptography;
@@ -93,6 +94,22 @@ private async Task<string> runCommand(HttpMethod method, string command, dynamic
9394
}
9495
catch (Exception e)
9596
{
97+
if (e is SharedInteropRequestFailedException interopException)
98+
{
99+
switch (interopException.StatusCode)
100+
{
101+
// Allow retry for potentially relevant 5XX responses.
102+
case HttpStatusCode.InternalServerError:
103+
case HttpStatusCode.BadGateway:
104+
case HttpStatusCode.ServiceUnavailable:
105+
case HttpStatusCode.GatewayTimeout:
106+
break;
107+
108+
default:
109+
throw;
110+
}
111+
}
112+
96113
if (retryCount-- > 0)
97114
{
98115
logger.LogError(e, "Shared interop request to {url} failed, retrying ({retries} remaining)", url, retryCount);
@@ -167,9 +184,12 @@ public RoomWithHostId(MultiplayerRoom room)
167184
[Serializable]
168185
private class SharedInteropRequestFailedException : HubException
169186
{
170-
private SharedInteropRequestFailedException(string message, Exception innerException)
187+
public readonly HttpStatusCode StatusCode;
188+
189+
private SharedInteropRequestFailedException(HttpStatusCode statusCode, string message, Exception innerException)
171190
: base(message, innerException)
172191
{
192+
StatusCode = statusCode;
173193
}
174194

175195
public static async Task<SharedInteropRequestFailedException> Create(string url, HttpResponseMessage response)
@@ -187,7 +207,8 @@ public static async Task<SharedInteropRequestFailedException> Create(string url,
187207
}
188208

189209
// Outer exception message is serialised to clients, inner exception is logged to the server and NOT serialised to the client.
190-
return new SharedInteropRequestFailedException(errorMessage, new Exception($"Shared interop request to {url} failed with {response.StatusCode} ({response.ReasonPhrase})."));
210+
return new SharedInteropRequestFailedException(response.StatusCode, errorMessage,
211+
new Exception($"Shared interop request to {url} failed with {response.StatusCode} ({response.ReasonPhrase})."));
191212
}
192213

193214
[Serializable]

0 commit comments

Comments
 (0)