Skip to content

Commit

Permalink
fix: Ensure to properly log re-connection to dev-server
Browse files Browse the repository at this point in the history
  • Loading branch information
dr1rrb committed Aug 6, 2024
1 parent 03dd444 commit d53787e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
24 changes: 12 additions & 12 deletions src/Uno.UI.RemoteControl/HotReload/HotReloadStatusView.Entries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ internal record DevServerEntry() : HotReloadLogEntry(EntrySource.DevServer, -1,
var (iconState, desc) = (oldStatus, newStatus) switch
{
(_, { State: ConnectionState.NoServer }) => (EntryIcon.Error, "No endpoint found"),
(_, { State: ConnectionState.Connecting }) => (EntryIcon.Loading, "Connecting..."),
({ State: not ConnectionState.ConnectionTimeout }, { State: ConnectionState.ConnectionTimeout }) => (EntryIcon.Error, "Timeout"),
({ State: not ConnectionState.ConnectionFailed }, { State: ConnectionState.ConnectionFailed }) => (EntryIcon.Error, "Connection error"),
(not null, { State: ConnectionState.Connecting }) => (EntryIcon.Loading, "Connecting..."),
(null or { State: not ConnectionState.ConnectionTimeout }, { State: ConnectionState.ConnectionTimeout }) => (EntryIcon.Error, "Timeout"),
(null or { State: not ConnectionState.ConnectionFailed }, { State: ConnectionState.ConnectionFailed }) => (EntryIcon.Error, "Connection error"),

({ IsVersionValid: not false }, { IsVersionValid: false }) => (EntryIcon.Warning, "Version mismatch"),
({ InvalidFrames.Count: 0 }, { InvalidFrames.Count: > 0 }) => (EntryIcon.Warning, "Unknown messages"),
({ MissingRequiredProcessors.IsEmpty: true }, { MissingRequiredProcessors.IsEmpty: false }) => (EntryIcon.Warning, "Processors missing"),
(null or { IsVersionValid: not false }, { IsVersionValid: false }) => (EntryIcon.Warning, "Version mismatch"),
(null or { InvalidFrames.Count: 0 }, { InvalidFrames.Count: > 0 }) => (EntryIcon.Warning, "Unknown messages"),
(null or { MissingRequiredProcessors.IsEmpty: true }, { MissingRequiredProcessors.IsEmpty: false }) => (EntryIcon.Warning, "Processors missing"),

({ KeepAlive.State: KeepAliveState.Idle or KeepAliveState.Ok }, { KeepAlive.State: KeepAliveState.Late }) => (EntryIcon.Error, "Connection lost (>1000ms)"),
({ KeepAlive.State: KeepAliveState.Idle or KeepAliveState.Ok }, { KeepAlive.State: KeepAliveState.Lost }) => (EntryIcon.Error, "Connection lost (>1s)"),
Expand Down Expand Up @@ -139,14 +139,14 @@ public enum EntrySource
public enum EntryIcon
{
// Kind
Loading = 0x1,
Success = 0x2,
Warning = 0x3,
Error = 0x4,
Loading = 1 << 0,
Success = 1 << 1,
Warning = 1 << 2,
Error = 1 << 3,

// Source
Connection = 0x1 << 8,
HotReload = 0x2 << 8,
Connection = 1 << 8,
HotReload = 2 << 8,
}


Expand Down
8 changes: 5 additions & 3 deletions src/Uno.UI.RemoteControl/RemoteControlClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@ public void RegisterPreProcessor(IRemoteControlPreProcessor preprocessor)
{
if (TryParse(srv.endpoint, srv.port, isHttps, out var serverUri))
{
// Note: If we have a preferred endpoint (last known to be successful), we delay a bit the connection to other endpoints.
// This is to reduce the number of (task cancelled / socket) exceptions at startup by giving a chance to the preferred endpoint to succeed first.
var cts = new CancellationTokenSource();
var delay = preferred is null || preferred.Equals(srv.endpoint, StringComparison.OrdinalIgnoreCase) ? 0 : 1000;
var task = Connect(serverUri, delay, cts.Token);
Expand Down Expand Up @@ -266,13 +268,13 @@ public void RegisterPreProcessor(IRemoteControlPreProcessor preprocessor)
return null;
}

// Remove the completed task from the pending list, no matter its completion status
var (_, endpoint, _) = pending[task];

// Remove the completed task from the pending list, no matter its completion status
pending.Remove(task);

// If the connection is successful, break the loop
if (task.IsCompleted
&& ((Task<Connection?>)task).Result is { Socket: not null } successfulConnection)
if (task is Task<Connection?> { IsCompleted: true, Result: { Socket: not null } successfulConnection })
{
ApplicationData.Current.LocalSettings.Values[lastEndpointKey] = endpoint;

Expand Down

0 comments on commit d53787e

Please sign in to comment.