0

Just upgraded from MassTransit 6.3.2 to 7.2.4. I'm using .Net Core 5.

The following unit test works fine before the upgrade but fails after.

using var harness = new InMemoryTestHarness();
       
harness.Consumer(() => new MockedxxxService(), xxxEndPoint);

harness.Start().Wait();

IBus endpoint = harness.Bus;

var tasks = new System.Collections.Concurrent.ConcurrentBag<Task<string>>();
var result = Parallel.For(0, 100, index =>
{
    var sut = new xxxRetriever(..., endpoint, ...);
    tasks.Add(sut.Getxxx(paramx));
});

Assert.True(result.IsCompleted);

await Task.WhenAll(tasks);

The code in the xxxRetriever class looks like this.

public async Task<string> Getxxx(string paramx)
{

   try
   {
      var serviceAddress = new Uri("queue:" + ...);

      var xxxService = _busService.CreateRequestClient<xxxContract>(serviceAddress, TimeSpan.FromMilliseconds(xxx));
       var xxxResponse = await xxxService.GetResponse<xxxResultContract>(new
       {
           ...
       }).ConfigureAwait(false);

     ....
   }
}

The endpoint is injected into the class as an IBus.

The mocked service looks like this.

public class MockedxxxService : IConsumer<xxxContract>
{

    public async Task Consume(ConsumeContext<xxxContract> context)
    {
        await context.RespondAsync<xxxResultContract>(new { ... } } });
    }
}

The tests run fine when we limit the number of tasks to about 30. But above that it fails consistently with the message "Timeout waiting for response, RequestId: ...".

Any help would be appreciated.

Theodor Zoulias
  • 34,835
  • 7
  • 69
  • 104
Karen
  • 1
  • 2

2 Answers2

0

It might be related to contention in the TPL, but that would only be a guess. You might be able to configure increase the concurrency limit on the bus and see if that helps:

harness.OnConfigureInMemoryBus += c =>
{
    c.Host(h => h.TransportConcurrencyLimit = 100);
};

That's a guess, but it might be related since it's load specific.

Obviously, this should be called prior to calling Start on the hardness (which should be awaited, instead of using .Wait() by the way).

Chris Patterson
  • 28,659
  • 3
  • 47
  • 59
0

After much investigation, we found that this was caused by the way .Net 5 handles thread creation. See ThreadPool.SetMinThreads does not create any new threads

We primed the thread pool before the test and that fixed the issue. Not sure why this worked correctly in .Net 5 under MassTransit 6, but it's working now.

Karen
  • 1
  • 2