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

Ensure duplicate discovery urls override previous url instead of causing exception #1903

Merged
merged 1 commit into from
Nov 21, 2022
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ private async Task<List<ApplicationRegistrationModel>> DiscoverServersAsync(
request.Token.ThrowIfCancellationRequested();
var resolved = await ep.TryResolveAsync();
var url = new Uri($"opc.tcp://" + resolved);
discoveryUrls.Add(ep, url);
discoveryUrls.AddOrUpdate(ep, url);
}
request.Token.ThrowIfCancellationRequested();

Expand Down Expand Up @@ -426,16 +426,18 @@ private async Task<List<ApplicationRegistrationModel>> DiscoverServersAsync(
/// <returns></returns>
private async Task<Dictionary<IPEndPoint, Uri>> GetDiscoveryUrlsAsync(
IEnumerable<Uri> discoveryUrls) {
var result = new Dictionary<IPEndPoint, Uri>();
if (discoveryUrls?.Any() ?? false) {
var results = await Task.WhenAll(discoveryUrls
.Select(GetHostEntryAsync)
.ToArray());
return results
foreach (var entry in results
.SelectMany(v => v)
.Where(a => a.Item2 != null)
.ToDictionary(k => k.Item1, v => v.Item2);
.Where(a => a.Item2 != null)) {
result.AddOrUpdate(entry.Item1, entry.Item2);
}
}
return new Dictionary<IPEndPoint, Uri>();
return result;
}

/// <summary>
Expand Down