Skip to content

Commit 5e4288a

Browse files
author
Marcus Griep
committed
Fix Nullable Supervisor Strategy constructors
In chaining to other constructors, the constructors for the `AllForOne` and `OneForOne` strategies pull timeouts from `TimeSpan`s using the `Milliseconds` property. This is not the correct behavior for `TimeSpan` values greater than or equal to 1 second as it provides only the milliseconds portion of the timespan. Instead, use the `TotalMilliseconds` property and cast it to an `int`.
1 parent eee0cd5 commit 5e4288a

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/core/Akka/Actor/SupervisorStrategy.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ public IDecider Decider
231231
/// <param name="withinTimeRange">duration of the time window for maxNrOfRetries, Duration.Inf means no window.</param>
232232
/// <param name="localOnlyDecider">mapping from Exception to <see cref="Directive" /></param>
233233
public OneForOneStrategy(int? maxNrOfRetries, TimeSpan? withinTimeRange, Func<Exception, Directive> localOnlyDecider)
234-
: this(maxNrOfRetries.GetValueOrDefault(-1), withinTimeRange.GetValueOrDefault(Timeout.InfiniteTimeSpan).Milliseconds, localOnlyDecider)
234+
: this(maxNrOfRetries.GetValueOrDefault(-1), (int) withinTimeRange.GetValueOrDefault(Timeout.InfiniteTimeSpan).TotalMilliseconds, localOnlyDecider)
235235
{
236236
//Intentionally left blank
237237
}
@@ -248,7 +248,7 @@ public OneForOneStrategy(int? maxNrOfRetries, TimeSpan? withinTimeRange, Func<Ex
248248
/// <param name="withinTimeRange">duration of the time window for maxNrOfRetries, Duration.Inf means no window.</param>
249249
/// <param name="decider">mapping from Exception to <see cref="Directive" /></param>
250250
public OneForOneStrategy(int? maxNrOfRetries, TimeSpan? withinTimeRange, IDecider decider)
251-
: this(maxNrOfRetries.GetValueOrDefault(-1), withinTimeRange.GetValueOrDefault(Timeout.InfiniteTimeSpan).Milliseconds, decider)
251+
: this(maxNrOfRetries.GetValueOrDefault(-1), (int) withinTimeRange.GetValueOrDefault(Timeout.InfiniteTimeSpan).TotalMilliseconds, decider)
252252
{
253253
//Intentionally left blank
254254
}
@@ -265,7 +265,8 @@ public OneForOneStrategy(int? maxNrOfRetries, TimeSpan? withinTimeRange, IDecide
265265
/// <param name="withinTimeMilliseconds">duration in milliseconds of the time window for <paramref name="maxNrOfRetries"/>, negative values means no window.</param>
266266
/// <param name="localOnlyDecider">Mapping from an <see cref="Exception"/> to <see cref="Directive"/></param>
267267
/// <param name="loggingEnabled">If <c>true</c> failures will be logged</param>
268-
public OneForOneStrategy(int maxNrOfRetries, int withinTimeMilliseconds, Func<Exception, Directive> localOnlyDecider, bool loggingEnabled = true) : this(maxNrOfRetries,withinTimeMilliseconds,new LocalOnlyDecider(localOnlyDecider),loggingEnabled)
268+
public OneForOneStrategy(int maxNrOfRetries, int withinTimeMilliseconds, Func<Exception, Directive> localOnlyDecider, bool loggingEnabled = true)
269+
: this(maxNrOfRetries, withinTimeMilliseconds, new LocalOnlyDecider(localOnlyDecider), loggingEnabled)
269270
{
270271
//Intentionally left blank
271272
}
@@ -403,7 +404,7 @@ public IDecider Decider
403404
/// <param name="withinTimeRange">duration of the time window for maxNrOfRetries, <see cref="Timeout.InfiniteTimeSpan"/> means no window.</param>
404405
/// <param name="localOnlyDecider">mapping from Exception to <see cref="Directive"/></param>
405406
public AllForOneStrategy(int? maxNrOfRetries, TimeSpan? withinTimeRange, Func<Exception, Directive> localOnlyDecider)
406-
: this(maxNrOfRetries.GetValueOrDefault(-1), withinTimeRange.GetValueOrDefault(Timeout.InfiniteTimeSpan).Milliseconds, localOnlyDecider)
407+
: this(maxNrOfRetries.GetValueOrDefault(-1), (int) withinTimeRange.GetValueOrDefault(Timeout.InfiniteTimeSpan).TotalMilliseconds, localOnlyDecider)
407408
{
408409
//Intentionally left blank
409410
}
@@ -420,7 +421,7 @@ public AllForOneStrategy(int? maxNrOfRetries, TimeSpan? withinTimeRange, Func<Ex
420421
/// <param name="withinTimeRange">duration of the time window for maxNrOfRetries, <see cref="Timeout.InfiniteTimeSpan"/> means no window.</param>
421422
/// <param name="decider">mapping from Exception to <see cref="Directive"/></param>
422423
public AllForOneStrategy(int? maxNrOfRetries, TimeSpan? withinTimeRange, IDecider decider)
423-
: this(maxNrOfRetries.GetValueOrDefault(-1), withinTimeRange.GetValueOrDefault(Timeout.InfiniteTimeSpan).Milliseconds, decider)
424+
: this(maxNrOfRetries.GetValueOrDefault(-1), (int) withinTimeRange.GetValueOrDefault(Timeout.InfiniteTimeSpan).TotalMilliseconds, decider)
424425
{
425426
//Intentionally left blank
426427
}

0 commit comments

Comments
 (0)