Skip to content

Commit

Permalink
Re-try when using HTTP API to close a connection and an error happens
Browse files Browse the repository at this point in the history
  • Loading branch information
lukebakken committed May 23, 2024
1 parent 3efd797 commit d4730c5
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions projects/Test/Common/Util.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,29 +67,32 @@ public static async Task CloseConnectionAsync(IConnection conn)
connectionToClose = connections.Where(c0 =>
string.Equals((string)c0.ClientProperties["connection_name"], conn.ClientProvidedName,
StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault();

if (connectionToClose == null)
{
tries++;
}
else
{
break;
}
}
catch (ArgumentNullException)
{
// Sometimes we see this in GitHub CI
tries++;
continue;
}
} while (tries <= 30);

if (connectionToClose != null)
{
try
{
await s_managementClient.CloseConnectionAsync(connectionToClose);
return;
}
catch (UnexpectedHttpStatusCodeException)
{
tries++;
}
}
} while (tries <= 10);

if (connectionToClose == null)
{
throw new InvalidOperationException($"Could not delete connection: '{conn.ClientProvidedName}'");
}

await s_managementClient.CloseConnectionAsync(connectionToClose);
}
}
}

0 comments on commit d4730c5

Please sign in to comment.