Report CultNet failures during connection
This commit is contained in:
parent
6be0573ffc
commit
455dcd8f9e
2 changed files with 39 additions and 4 deletions
|
|
@ -764,7 +764,11 @@ namespace GameCult.Mesh
|
||||||
|
|
||||||
var (host, port) = CultNetSchemaWriteForwarder.ParseEndpoint(endpoint);
|
var (host, port) = CultNetSchemaWriteForwarder.ParseEndpoint(endpoint);
|
||||||
client.Connect(host, port);
|
client.Connect(host, port);
|
||||||
await WaitForSnapshotClientConnectionAsync(client, endpoint, resolvedOptions.ConnectTimeout)
|
await WaitForSnapshotClientConnectionAsync(
|
||||||
|
client,
|
||||||
|
endpoint,
|
||||||
|
resolvedOptions.ConnectTimeout,
|
||||||
|
(client as ICultNetSchemaClientHealth)?.BackgroundFailure)
|
||||||
.ConfigureAwait(false);
|
.ConfigureAwait(false);
|
||||||
client.SendCultNet(new CultNetSnapshotRequestMessage
|
client.SendCultNet(new CultNetSnapshotRequestMessage
|
||||||
{
|
{
|
||||||
|
|
@ -871,11 +875,19 @@ namespace GameCult.Mesh
|
||||||
internal static async Task WaitForSnapshotClientConnectionAsync(
|
internal static async Task WaitForSnapshotClientConnectionAsync(
|
||||||
ICultNetSchemaClient client,
|
ICultNetSchemaClient client,
|
||||||
string endpoint,
|
string endpoint,
|
||||||
TimeSpan timeout)
|
TimeSpan timeout,
|
||||||
|
Task<Exception>? backgroundFailure = null)
|
||||||
{
|
{
|
||||||
var deadline = DateTimeOffset.UtcNow + timeout;
|
var deadline = DateTimeOffset.UtcNow + timeout;
|
||||||
while (!client.Connected)
|
while (!client.Connected)
|
||||||
{
|
{
|
||||||
|
if (backgroundFailure?.IsCompleted == true)
|
||||||
|
{
|
||||||
|
var error = await backgroundFailure.ConfigureAwait(false);
|
||||||
|
throw new InvalidOperationException(
|
||||||
|
$"CultNet snapshot client failed while connecting to {endpoint}.",
|
||||||
|
error);
|
||||||
|
}
|
||||||
if (DateTimeOffset.UtcNow >= deadline)
|
if (DateTimeOffset.UtcNow >= deadline)
|
||||||
throw new TimeoutException($"Timed out connecting to CultNet snapshot endpoint {endpoint}.");
|
throw new TimeoutException($"Timed out connecting to CultNet snapshot endpoint {endpoint}.");
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2674,6 +2674,26 @@ public sealed class CultMeshStreamingTests
|
||||||
failure.Which.Message.Should().Contain("127.0.0.1:3075");
|
failure.Which.Message.Should().Contain("127.0.0.1:3075");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task SnapshotHelpers_SurfaceBackgroundClientFailureWhileConnecting()
|
||||||
|
{
|
||||||
|
var options = new CultMeshSnapshotRequestOptions
|
||||||
|
{
|
||||||
|
ConnectTimeout = TimeSpan.FromSeconds(30),
|
||||||
|
CreateClient = () => new FailedBackgroundSchemaClient(
|
||||||
|
new FormatException("malformed handshake"),
|
||||||
|
connected: false)
|
||||||
|
};
|
||||||
|
|
||||||
|
Func<Task> act = async () => await CultMesh.FetchSnapshotAsync(
|
||||||
|
"rudp://127.0.0.1:3075",
|
||||||
|
options);
|
||||||
|
|
||||||
|
var failure = await act.Should().ThrowAsync<InvalidOperationException>();
|
||||||
|
failure.Which.InnerException.Should().BeOfType<FormatException>();
|
||||||
|
failure.Which.Message.Should().Contain("connecting");
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public async Task SnapshotHelpers_DecodeSameSchemaAliasFromForeignSchemaId()
|
public async Task SnapshotHelpers_DecodeSameSchemaAliasFromForeignSchemaId()
|
||||||
{
|
{
|
||||||
|
|
@ -3838,15 +3858,18 @@ internal sealed class MeshSnapshotSchemaClient : ICultNetSchemaClient
|
||||||
|
|
||||||
internal sealed class FailedBackgroundSchemaClient : ICultNetSchemaClient, ICultNetSchemaClientHealth
|
internal sealed class FailedBackgroundSchemaClient : ICultNetSchemaClient, ICultNetSchemaClientHealth
|
||||||
{
|
{
|
||||||
public FailedBackgroundSchemaClient(Exception error)
|
private readonly bool _connected;
|
||||||
|
|
||||||
|
public FailedBackgroundSchemaClient(Exception error, bool connected = true)
|
||||||
{
|
{
|
||||||
|
_connected = connected;
|
||||||
BackgroundFailure = Task.FromResult(error);
|
BackgroundFailure = Task.FromResult(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Connected { get; private set; }
|
public bool Connected { get; private set; }
|
||||||
public Task<Exception> BackgroundFailure { get; }
|
public Task<Exception> BackgroundFailure { get; }
|
||||||
|
|
||||||
public void Connect(string host, int port) => Connected = true;
|
public void Connect(string host, int port) => Connected = _connected;
|
||||||
|
|
||||||
public void SendCultNet<T>(T message) where T : ICultNetSchemaMessage
|
public void SendCultNet<T>(T message) where T : ICultNetSchemaMessage
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue