Skip to content

Commit 4936772

Browse files
committed
enable changing the wait timeout for #391
1 parent d4af2ba commit 4936772

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

playground/Playground/RealisticUnitOfWorkBenchmark.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1477,16 +1477,16 @@ public void WarmUp()
14771477
[Benchmark]
14781478
public object Grace() => Measure(_grace);
14791479

1480-
[Benchmark]
1480+
// [Benchmark]
14811481
public object Grace_MsDIAdapter() => Measure(_graceMsDi);
14821482

1483-
[Benchmark]
1483+
// [Benchmark]
14841484
public object Lamar_MsDI() => Measure(_lamarMsDi);
14851485

1486-
[Benchmark]
1486+
// // [Benchmark]
14871487
public object Autofac() => Measure(_autofac);
14881488

1489-
[Benchmark]
1489+
// [Benchmark]
14901490
public object Autofac_MsDIAdapter() => Measure(_autofacMsDi);
14911491
}
14921492
}

src/DryIoc/Container.cs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12010,7 +12010,9 @@ internal object TryGetOrAddViaFactoryDelegate(int id, FactoryDelegate createValu
1201012010
return result;
1201112011
}
1201212012

12013-
internal const uint WaitForItemIsSetTimeout = 5000;
12013+
/// <summary>The amount of time to wait for the other party to create the scoped (or singleton) service.
12014+
/// The default value of 5000 ticks rougly corresponds to the 5 seconds.</summary>
12015+
public static uint WaitForScopedServiceIsCreatedTimeoutTicks = 5000;
1201412016

1201512017
internal static object WaitForItemIsSet(ImMapEntry<object> itemRef)
1201612018
{
@@ -12023,8 +12025,8 @@ internal static object WaitForItemIsSet(ImMapEntry<object> itemRef)
1202312025
while (itemRef.Value == NoItem)
1202412026
{
1202512027
spinWait.SpinOnce();
12026-
if (tickCount - tickStart > WaitForItemIsSetTimeout)
12027-
Throw.It(Error.WaitForScopedServiceIsCreatedTimeoutExpired, WaitForItemIsSetTimeout);
12028+
if (tickCount - tickStart > WaitForScopedServiceIsCreatedTimeoutTicks)
12029+
Throw.It(Error.WaitForScopedServiceIsCreatedTimeoutExpired, WaitForScopedServiceIsCreatedTimeoutTicks);
1202812030
tickCount = (uint)Environment.TickCount;
1202912031
}
1203012032

@@ -13501,13 +13503,13 @@ public static readonly int
1350113503
UnableToInterpretTheNestedLambda = Of(
1350213504
"Unable to interpret the nested lambda with Body:" + NewLine +
1350313505
"{0}"),
13504-
WaitForScopedServiceIsCreatedTimeoutExpired = Of(
13505-
"DryIoc have waited for the creation of the scoped service by 'other party' for the {0} ticks without the success." + NewLine +
13506-
"It means that either the 'other party' is the parallel thread which has started! but unable to finish the creation of the service in the provided amount of time." + NewLine +
13507-
"Or more likely there is an undetected recursive dependency and the 'other party' is the same thread." + NewLine +
13508-
"Another reason may be that the previous scoped service resolution is failed with the exception and the exception was CATCHED " + NewLine +
13509-
"but you are trying to resolve the failed service again." + NewLine +
13510-
"That's why for all these reasons we have a timeout to prevent the hanging due to the infinite waiting.");
13506+
WaitForScopedServiceIsCreatedTimeoutExpired = Of(
13507+
"DryIoc has waited for the creation of the scoped (or singleton) service by 'other party' for the {0} ticks without the completion. " + NewLine +
13508+
"It means that either the 'other party' is the parallel thread which has started (!) but unable to finish the creation of the service in the provided amount of time. " + NewLine +
13509+
"Or more likely the 'other party' is the same thread and there is an undetected recursive dependency or " + NewLine +
13510+
"the scoped service creation is failed with the exception and the exception was catched (!) but you are trying to resolve the failed service again. " + NewLine +
13511+
"For all those reasons DryIoc has a timeout to prevent the infinite waiting. " + NewLine +
13512+
$"You may change the default timeout via `Scope.{nameof(Scope.WaitForScopedServiceIsCreatedTimeoutTicks)}=NewValue`");
1351113513

1351213514
#pragma warning restore 1591 // "Missing XML-comment"
1351313515

0 commit comments

Comments
 (0)