File tree Expand file tree Collapse file tree 2 files changed +22
-1
lines changed
src/Polly.Core/CircuitBreaker/Controller
test/Polly.Core.Tests/CircuitBreaker/Controller Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -26,7 +26,7 @@ public Task ScheduleTask(Func<Task> taskFactory)
2626 }
2727#endif
2828
29- var source = new TaskCompletionSource < object > ( ) ;
29+ var source = new TaskCompletionSource < object > ( TaskCreationOptions . RunContinuationsAsynchronously ) ;
3030
3131 _tasks . Enqueue ( new Entry ( taskFactory , source ) ) ;
3232 _semaphore . Release ( ) ;
Original file line number Diff line number Diff line change @@ -129,6 +129,27 @@ public void Dispose_WhenScheduledTaskExecuting()
129129#pragma warning restore xUnit1031
130130 }
131131
132+ [ Fact ]
133+ public void ScheduleTask_InlineContinuationDoesNotDeadlock ( )
134+ {
135+ var timeout = TimeSpan . FromMilliseconds ( 250 ) ;
136+ using var scheduler = new ScheduledTaskExecutor ( ) ;
137+
138+ var firstTask = scheduler . ScheduleTask ( ( ) => Task . CompletedTask ) ;
139+
140+ var continuationTask = firstTask . ContinueWith (
141+ _ =>
142+ {
143+ var secondTask = scheduler . ScheduleTask ( ( ) => Task . CompletedTask ) ;
144+ secondTask . Wait ( timeout ) ;
145+ } ,
146+ CancellationToken ,
147+ TaskContinuationOptions . ExecuteSynchronously ,
148+ TaskScheduler . Default ) ;
149+
150+ continuationTask . Wait ( timeout ) . ShouldBeTrue ( ) ;
151+ }
152+
132153 [ Fact ]
133154 public async Task Dispose_EnsureNoBackgroundProcessing ( )
134155 {
You can’t perform that action at this time.
0 commit comments