0
0

Don't attempt reconnection process if connection state is reportedly still open

This commit is contained in:
Rhys Ickeringill
2025-12-28 18:19:50 +11:00
parent 7ab61f8ff9
commit 8acbab1832

View File

@@ -65,7 +65,7 @@ internal class PostgreSQLNotificationConfigurationReloader : Microsoft.Extension
_logger?.LogWarning(e, "Exception while waiting for notifications on channel '{channel}'", _options.ChannelName);
}
}
while (await IsReconnectionPossible(stoppingToken));
while (ConnectionState.Open == dbConnection.State || await IsReconnectionPossible(stoppingToken));
_logger?.LogWarning("Giving up listening for notifications on channel '{channel}' because reconnection attempts exhausted. Configuration updates from database will no longer occur", _options.ChannelName);
}
@@ -125,7 +125,7 @@ internal class PostgreSQLNotificationConfigurationReloader : Microsoft.Extension
var cancelableTask = Task.Delay(Timeout.Infinite, _cts.Token);
var completedTask = await Task.WhenAny(delayTask, cancelableTask).ConfigureAwait(false);
if (completedTask == delayTask) // If the completed task is the delayTask, we reached debounce delay, proceed with reload
if (ReferenceEquals(completedTask, delayTask)) // If the completed task is the delayTask, we reached debounce delay, proceed with reload
{
_configProvider.OnReload();
}
@@ -165,7 +165,7 @@ internal class PostgreSQLNotificationConfigurationReloader : Microsoft.Extension
var backoffTask = Task.Delay(_options.InitialReconnectionDelay * (1 << i), stoppingToken);
var completedTask = await Task.WhenAny(backoffTask, canConnectTask);
if (completedTask == canConnectTask) // connect finished first
if (ReferenceEquals(completedTask, canConnectTask)) // connect finished first
{
if (await canConnectTask) return true; // if can connect return immediately
await backoffTask; // connect failed, wait for backoff time before trying again