Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix the discovered processor list additive (backport #18745) #18755

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/Uno.UI.RemoteControl.Host/RemoteControlServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ internal class RemoteControlServer : IRemoteControlServer, IDisposable
private static readonly Dictionary<string, (AssemblyLoadContext Context, int Count)> _loadContexts = new();
private static readonly Dictionary<string, string> _resolveAssemblyLocations = new();
private readonly Dictionary<string, IServerProcessor> _processors = new();
private readonly List<DiscoveredProcessor> _discoveredProcessors = new();
private readonly CancellationTokenSource _ct = new();

private WebSocket? _socket;
Expand Down Expand Up @@ -257,7 +258,6 @@ private async Task ProcessPingFrame(Frame frame)
private async Task ProcessDiscoveryFrame(Frame frame)
{
var assemblies = new List<(string path, System.Reflection.Assembly assembly)>();
var discoveredProcessors = new List<DiscoveredProcessor>();
try
{
var msg = JsonConvert.DeserializeObject<ProcessorsDiscovery>(frame.Content)!;
Expand Down Expand Up @@ -358,12 +358,12 @@ private async Task ProcessDiscoveryFrame(Frame frame)
{
if (ActivatorUtilities.CreateInstance(_serviceProvider, processor.ProcessorType, parameters: new[] { this }) is IServerProcessor serverProcessor)
{
discoveredProcessors.Add(new(asm.path, processor.ProcessorType.FullName!, VersionHelper.GetVersion(processor.ProcessorType), IsLoaded: true));
_discoveredProcessors.Add(new(asm.path, processor.ProcessorType.FullName!, VersionHelper.GetVersion(processor.ProcessorType), IsLoaded: true));
RegisterProcessor(serverProcessor);
}
else
{
discoveredProcessors.Add(new(asm.path, processor.ProcessorType.FullName!, VersionHelper.GetVersion(processor.ProcessorType), IsLoaded: false));
_discoveredProcessors.Add(new(asm.path, processor.ProcessorType.FullName!, VersionHelper.GetVersion(processor.ProcessorType), IsLoaded: false));
if (this.Log().IsEnabled(LogLevel.Debug))
{
this.Log().LogDebug("Failed to create server processor {ProcessorType}", processor.ProcessorType);
Expand All @@ -372,7 +372,7 @@ private async Task ProcessDiscoveryFrame(Frame frame)
}
catch (Exception error)
{
discoveredProcessors.Add(new(asm.path, processor.ProcessorType.FullName!, VersionHelper.GetVersion(processor.ProcessorType), IsLoaded: false, LoadError: error.ToString()));
_discoveredProcessors.Add(new(asm.path, processor.ProcessorType.FullName!, VersionHelper.GetVersion(processor.ProcessorType), IsLoaded: false, LoadError: error.ToString()));
if (this.Log().IsEnabled(LogLevel.Error))
{
this.Log().LogError(error, "Failed to create server processor {ProcessorType}", processor.ProcessorType);
Expand Down Expand Up @@ -404,7 +404,7 @@ private async Task ProcessDiscoveryFrame(Frame frame)
{
await SendFrame(new ProcessorsDiscoveryResponse(
assemblies.Select(asm => asm.path).ToImmutableList(),
discoveredProcessors.ToImmutableList()));
_discoveredProcessors.ToImmutableList()));
}
}

Expand Down
14 changes: 13 additions & 1 deletion src/Uno.UI.RemoteControl/RemoteControlClient.Status.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,19 @@ public void ReportServerProcessors(ProcessorsDiscoveryResponse response)

static IEnumerable<MissingProcessor> GetMissingServerProcessors(ImmutableHashSet<ProcessorInfo> requiredProcessors, ProcessorsDiscoveryResponse response)
{
var loaded = response.Processors.ToDictionary(p => p.Type, StringComparer.OrdinalIgnoreCase);
var loaded = response
.Processors
.GroupBy(p => p.Type, StringComparer.OrdinalIgnoreCase)
// If a processors is being loaded multiple times, we prefer to keep the result that has no error.
.Select(g => g
.OrderBy(p => p switch
{
{ LoadError: not null } => 0,
{ IsLoaded: false } => 1,
_ => 2
})
.Last())
.ToDictionary(p => p.Type, StringComparer.OrdinalIgnoreCase);
foreach (var required in requiredProcessors)
{
if (!loaded.TryGetValue(required.TypeFullName, out var actual))
Expand Down
Loading