From 1cbf2743b3fe20abedb1629a207bb44dd0b7c0e8 Mon Sep 17 00:00:00 2001 From: RAMAKANT BHANDARU Date: Mon, 13 May 2024 10:54:02 -0400 Subject: [PATCH 1/2] Open the closed connection due to network issues or any other db logout user issues etc. --- src/DurableTask.SqlServer/SqlUtils.cs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/DurableTask.SqlServer/SqlUtils.cs b/src/DurableTask.SqlServer/SqlUtils.cs index a06ed2b..662b123 100644 --- a/src/DurableTask.SqlServer/SqlUtils.cs +++ b/src/DurableTask.SqlServer/SqlUtils.cs @@ -29,7 +29,7 @@ static class SqlUtils { return reader.IsDBNull(columnIndex) ? null : reader.GetString(columnIndex); } - + public static TaskMessage GetTaskMessage(this DbDataReader reader) { return new TaskMessage @@ -560,7 +560,7 @@ static async Task ExecuteSprocAndTraceAsync( var context = new SprocExecutionContext(); try { - return await WithRetry(() => executor(command), context, traceHelper, instanceId); + return await WithRetry(command, executor, context, traceHelper, instanceId); } finally { @@ -610,7 +610,7 @@ public static DateTime ToSqlUtcDateTime(this DateTime dateTime, DateTime default } } - static async Task WithRetry(Func> func, SprocExecutionContext context, LogHelper traceHelper, string? instanceId, int maxRetries = 5) + static async Task WithRetry(DbCommand command, Func> executor, SprocExecutionContext context, LogHelper traceHelper, string? instanceId, int maxRetries = 5) { context.RetryCount = 0; @@ -618,7 +618,12 @@ static async Task WithRetry(Func> func, SprocExecutionContext cont { try { - return await func(); + // Open connection if network blip caused it to close on a previous attempt + if (command.Connection.State != ConnectionState.Open) + { + await command.Connection.OpenAsync(); + } + return await executor(command); } catch (Exception e) { From 2d92f33762c62a31a4c0e8b4bae896fc32b8fbeb Mon Sep 17 00:00:00 2001 From: Chris Gillum Date: Tue, 4 Jun 2024 06:29:20 +0900 Subject: [PATCH 2/2] Update CHANGELOG.md --- CHANGELOG.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 182e88c..060bd91 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,12 @@ # Changelog -## v1.3.0 (Unreleased) +## v1.3.1 (Unreleased) + +### Updates + +* Fix SQL retry logic to open a new connection if a previous failure closed the connection ([#221](https://github.com/microsoft/durabletask-mssql/pull/221)) - contributed by [@microrama](https://github.com/microrama) + +## v1.3.0 ### Updates