From d4730c5c0ca14af8305935f8f58588e4cbb51f95 Mon Sep 17 00:00:00 2001 From: Luke Bakken Date: Thu, 23 May 2024 13:55:02 -0700 Subject: [PATCH] Re-try when using HTTP API to close a connection and an error happens --- projects/Test/Common/Util.cs | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/projects/Test/Common/Util.cs b/projects/Test/Common/Util.cs index a206744ca..e9afa4edf 100644 --- a/projects/Test/Common/Util.cs +++ b/projects/Test/Common/Util.cs @@ -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); } } }