1

Closed

Consider killing off the TaskFactory

description

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.
Closed Apr 4, 2013 at 3:35 PM by olegkap
Fixed in 24900

comments

olegkap wrote Apr 4, 2013 at 3:35 PM

Hey,

Thanks for this info.
I originally used TaskFactory since my understanding was that in .4.0 we should use it but I guess they still have bugs, and you right there is no difference between method to another one.

I just commited 24900 changeset so you take a look at it.

Thanks,
Oleg

GeertvanHorrik wrote Apr 4, 2013 at 4:08 PM

Excellent, thanks! When will the new version be released via nuget? :-)

olegkap wrote Apr 4, 2013 at 5:13 PM

I am not sure yet but will try to make it soon,
Busy with other projects at work which leaves me almost no time other then answering some e-mails :(

GeertvanHorrik wrote Apr 6, 2013 at 9:44 AM

I understand that you are busy, but I need this fix asap. Are there other things you are waiting for? Can I help you with something?

olegkap wrote Apr 6, 2013 at 5:45 PM

I just made a new release 2013.4.7 which actually tried to do for tomorrow.
I also updated NUGET so it should be available there as well.
Please let me know if you have any further problems.

Thanks,
Oleg

GeertvanHorrik wrote Apr 6, 2013 at 6:39 PM

Cool, thanks for your awesome support!