Skip to content

Commit b6d93c1

Browse files
authored
Fix SqlServerRetryPolicy GetNextDelay returning negative TimeSpan (#539)
1 parent 2cc2ce3 commit b6d93c1

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

src/Akka.Persistence.Sql/Db/AkkaPersistenceDataConnectionFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public AkkaPersistenceDataConnectionFactory(IProviderConfig<SnapshotTableConfigu
7979
_useCloneDataConnection = config.UseCloneConnection;
8080

8181
if (_opts.RetryPolicyOptions.RetryPolicy is null && _opts.ConnectionOptions.ProviderName!.ToLowerInvariant().StartsWith("sqlserver"))
82-
_opts = _opts.WithOptions( _opts.RetryPolicyOptions with { RetryPolicy = new SqlServerRetryPolicy() } );
82+
_opts = _opts.WithOptions( _opts.RetryPolicyOptions with { RetryPolicy = new AkkaSqlServerRetryPolicy() } );
8383

8484
_cloneConnection = new Lazy<AkkaDataConnection>(
8585
() => new AkkaDataConnection(
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// -----------------------------------------------------------------------
2+
// <copyright file="CustomSqlServerRetryPolicy.cs" company="Akka.NET Project">
3+
// Copyright (C) 2013-2023 .NET Foundation <https://github.com/akkadotnet/akka.net>
4+
// </copyright>
5+
// -----------------------------------------------------------------------
6+
7+
using System;
8+
using System.Collections.Generic;
9+
using LinqToDB.DataProvider.SqlServer;
10+
11+
namespace Akka.Persistence.Sql.Db;
12+
13+
public class AkkaSqlServerRetryPolicy: SqlServerRetryPolicy
14+
{
15+
public AkkaSqlServerRetryPolicy() { }
16+
public AkkaSqlServerRetryPolicy(int maxRetryCount) : base(maxRetryCount) { }
17+
public AkkaSqlServerRetryPolicy(
18+
int maxRetryCount,
19+
TimeSpan maxRetryDelay,
20+
double randomFactor,
21+
double exponentialBase,
22+
TimeSpan coefficient,
23+
ICollection<int>? errorNumbersToAdd)
24+
: base(maxRetryCount, maxRetryDelay, randomFactor, exponentialBase, coefficient, errorNumbersToAdd) { }
25+
26+
protected override TimeSpan? GetNextDelay(Exception lastException)
27+
{
28+
var nextDelay = base.GetNextDelay(lastException);
29+
return nextDelay is { TotalMilliseconds: < 0 } ? TimeSpan.Zero : nextDelay;
30+
}
31+
}

0 commit comments

Comments
 (0)