Closed michac closed 9 months ago
Great, thank you for all of the information! I suspect we can address this in the next minor release.
@michac - please see this PR - https://github.com/rabbitmq/rabbitmq-dotnet-client/pull/1388
Is that what you're thinking?
Yes, this is great, thank you!
@michac - thanks, I will test the PR using the project you provided.
@michac sure enough, my PR allows both connections to succeed in your test app.
Fixed by #1388
Describe the bug
CreateConnection will timeout if it's called on a thread with a non-default TaskScheduler that is blocked by the call to CreateConnection, for example a single threaded message pump.
Reproduction steps
I apologize for the use of the Akka library, which may make the example less clear. It is only there to demonstrate how CreateConnection behaves on a thread with the TaskScheduler overridden. I'm sure it could be reproduced with just a custom limited concurrency taskscheduler and little more knowledge than I have off the top of my head.
Here I'm showing CreateConnection working on the main thread, but then getting blocked when run in the background by the ConnectionTestActor.
https://github.com/michac/RabbitSchedulerTest
Expected behavior
It's not clear that CreateConnection is going to inherit any async context from the thread it's run on. I would expect the MainLoop to either have a dedicated thread or at least make sure it runs on the ThreadPool, which can be done by specifying the Default TaskScheduler in Task.Factory.StartNew.
I am remediating this for now by wrapping my calls to CreateConnection in a Task.Run to make sure the TaskScheduler is the ThreadPool.
Additional context
Here is an article on the risks with using StartNew for reference: https://blog.stephencleary.com/2013/08/startnew-is-dangerous.html