We are moving to NServiceBus for some of our parts of the software, and suddenly the library stopped working (connection timeouts). So after a few hours of double checking everything, I decided to download the source and try it myself.
I found that the Connect method spawns a new listener thread (ExecuteThread). In this thread (NET40), the TaskFactory is used. However, when ran in my NServiceBus node the thread nevers gets spawned though the max number of threads is not just 1.
I have changed the ExecuteThread from:
Task.Factory.StartNew(action, TaskCreationOptions.LongRunning);
To
ThreadPool.QueueUserWorkItem((o) => { action(); });
And now it works great again.
Now to prevent any discussion whether this is or not is a bug in NServiceBus, it seems that the TaskFactory is not able to spawn the thread where the ThreadPool is able to. I actually don't see any reason to use the TaskFactory here.
Comments: Fixed in 24900
I found that the Connect method spawns a new listener thread (ExecuteThread). In this thread (NET40), the TaskFactory is used. However, when ran in my NServiceBus node the thread nevers gets spawned though the max number of threads is not just 1.
I have changed the ExecuteThread from:
Task.Factory.StartNew(action, TaskCreationOptions.LongRunning);
To
ThreadPool.QueueUserWorkItem((o) => { action(); });
And now it works great again.
Now to prevent any discussion whether this is or not is a bug in NServiceBus, it seems that the TaskFactory is not able to spawn the thread where the ThreadPool is able to. I actually don't see any reason to use the TaskFactory here.
Comments: Fixed in 24900