title: MassTransit (over RabbitMQ) IServiceBus.Publish(...) hangs unexpectedly
body: <p>I'm developing web based solution using MassTransit + RabbitMQ. Some time ago I noticed that when I run my integration tests some of them start <strong>unexpectedly</strong> and <strong>very inconsistently</strong> hanging for a very loooong time.
  After short investigation I found out that my code hangs somewhere inside <em>ServiceBus.Publish(T message)</em> method.</p>
  
  <p>Unfortunately MassTransit documentation and blog posts that I found do not answer what is the reason and how to solve this problem. Hopefully here somebody could help to resolve it.</p>
  
  <p>Here is how I initialize my service bus:</p>
  
  <pre><code>ServiceBusFactory.New(sbc =&gt;
        {
          sbc.ReceiveFrom(busAddress);
          sbc.UseRabbitMq(r =&gt;
          {
            r.ConfigureHost(new Uri(busAddress),
              cfg =&gt;
              {
                if (!string.IsNullOrEmpty(busUser) &amp;&amp; !string.IsNullOrEmpty(busPass))
                {
                  cfg.SetPassword(busPass);
                  cfg.SetUsername(busUser);
                }
              });
          });
  
          sbc.UseControlBus();
          sbc.SetCreateMissingQueues(true);
          sbc.SetCreateTransactionalQueues(true);
          sbc.SetNetwork("workgroup");
          sbc.UseBsonSerializer();
          sbc.SetDefaultRetryLimit(2);
          sbc.SetDefaultTransactionTimeout(new TimeSpan(0, 0, timeoutSec));
  
          sbc.Validate();
        });
  </code></pre>
  
  <p><em>timeoutSec</em> value is 10
  Service bus is initialized once and registered in Autofac container.</p>
  
  <p>Publishing happens by calling <em>IServiceBus.Publish(...)</em> method.</p>
  
  <p>One of the solutions is to  wrap Publish(...) method into Task and use Task.Wait(...) method to enforce timeout but this does not look like a good solution.</p>
  
  <p>I would be really appreciated for any kind of help!</p>
  
  <p><strong>IMPORTANT UPDATE 2017-01-26:</strong> this question is related to <em>MT v2</em>. It seems that MT v3 has similar issue if one forgets "await". My problem is not related to "await" and currently (still) does not have a good solution (as far as I know). I would strongly recommend everyone to migrate to MT v3.</p>