Skip to content

Commit

Permalink
Fix redundant connect (#371)
Browse files Browse the repository at this point in the history
The logic had gotten a bit messed up in the recent service level change.
  • Loading branch information
einarmo authored Mar 14, 2023
1 parent b4078b5 commit 96022f6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
17 changes: 8 additions & 9 deletions Extractor/SessionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -309,32 +309,30 @@ private async Task<SessionRedundancyResult> CreateSessionWithRedundancy(string i
string? bestUrl = null;
byte bestServiceLevel = 0;

if (initialServiceLevel != null)
{
if (initialSession == null) throw new InvalidOperationException("InitialSession must be passed along with initialServiceLevel");
bestServiceLevel = initialServiceLevel.Value;
}

endpointUrls = endpointUrls.Prepend(initialUrl).Distinct().ToList();
log.LogInformation("Create session with redundant connections to {Urls}", string.Join(", ", endpointUrls));

ISession? activeSession = initialSession;

string? activeEndpoint = null;
if (activeSession != null)
{
if (initialServiceLevel == null) throw new InvalidOperationException("InitialServiceLevel required when initialSession is non-null");
if (EndpointUrl == null) throw new InvalidOperationException("EndpointUrl must be set if initialSession is passed");
bestUrl = EndpointUrl;
bestServiceLevel = initialServiceLevel.Value;
}

string? activeEndpoint = null;
var exceptions = new List<Exception>();

foreach (var url in endpointUrls)
{
try
{
ISession session;
if (url == EndpointUrl)
if (url == bestUrl && activeSession != null)
{
session = initialSession!;
session = activeSession;
}
else
{
Expand All @@ -359,6 +357,7 @@ private async Task<SessionRedundancyResult> CreateSessionWithRedundancy(string i
}
catch (Exception ex)
{
log.LogError("Failed to connect to endpoint {Url}: {Error}", url, ex.Message);
exceptions.Add(ex);
}
}
Expand Down
5 changes: 5 additions & 0 deletions manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ schema:
- "https://raw.githubusercontent.com/"

versions:
"2.15.1":
description: Fix connecting to redundant servers
changelog:
fixed:
- "Fix issue causing the extractor to only connect to alt endpoints"
"2.15.0":
description: Add live monitoring of ServiceLevel, variable subscription config
changelog:
Expand Down

0 comments on commit 96022f6

Please sign in to comment.