Polly-Samples icon indicating copy to clipboard operation
Polly-Samples copied to clipboard

Async demo 09: Never stops after running 14+ requests

Open kabua opened this issue 4 years ago • 2 comments

After running the demo a few times and allowing it to run for several request, 14+ times), the screen fills up with

Object name: 'System.Net.Http.HttpClient'.

The exception happens on line 159.

kabua avatar Apr 14 '21 17:04 kabua

Looks like when the loop ends by the CancellationToken being fired and the HttpClient is disposed of:

https://github.com/App-vNext/Polly-Samples/blob/88c3b8e8373bdefcf8012f1c09325f6de5ba2db0/PollyDemos/Async/AsyncDemo09_Wrap-Fallback-Timeout-WaitAndRetry.cs#L144

If there are any cancelled HTTP requests still pending to run, they'll try to use the now-disposed HttpClient, causing an ObjectDisposedException:

https://github.com/App-vNext/Polly-Samples/blob/88c3b8e8373bdefcf8012f1c09325f6de5ba2db0/PollyDemos/Async/AsyncDemo09_Wrap-Fallback-Timeout-WaitAndRetry.cs#L159

martincostello avatar Apr 14 '21 17:04 martincostello

Yes, that is correct.

However, the policy is configured to handle all exceptions and to run forever, and the policyWrap.ExecuteAsync() is accepting a cancellationToken but which appears not to be honoring.

Also, how would I write something like, handle all exceptions except for MyException? Something like: Policy.Handle<Exception>().ButNot<MyException>()...

Thanks.

kabua avatar Apr 14 '21 23:04 kabua

@peter-csala Something to consider when you get to migrating this demo.

martincostello avatar Sep 29 '23 10:09 martincostello

@martincostello Please assign to me, otherwise I will forget it :)

peter-csala avatar Sep 29 '23 11:09 peter-csala

After the V8 migration I can not reproduce the problem. The application can be stopped any time.

samples_issue_25

@martincostello I think we can close this issue if you agree.

peter-csala avatar Oct 12 '23 11:10 peter-csala