MassTransit/MassTransit — Issue #47: NullReferenceException on Send if RMQ connection fails
Author: haf
Created: 2011-11-08 10:21:36+00:00
State: open

```
13404 [12] INFO MassTransit.Messages (null) - SEND:rabbitmq://localhost/PongClient:Pong:
13407 [15] INFO MassTransit.Messages (null) - SEND:rabbitmq://localhost/PongClient:Pong:
13449 [11] INFO MassTransit.Messages (null) - SEND:rabbitmq://localhost/PongClient:Fault`2:
13449 [6] INFO MassTransit.Messages (null) - SEND:rabbitmq://localhost/PongClient:Fault`2:
13474 [11] ERROR MassTransit.Context.ServiceBusReceiveContext (null) - 'System.Action`1[[MassTransit.IConsumeContext, Ma
ssTransit, Version=2.0.1.0, Culture=neutral, PublicKeyToken=null]]' threw an exception consuming message 'MassTransit.Co
ntext.ReceiveContext'
MassTransit.Exceptions.SendException: rabbitmq://localhost/PongClient => An exception was thrown during Send ---> System
.NullReferenceException: Object reference not set to an instance of an object.
at MassTransit.Transports.RabbitMq.OutboundRabbitMqTransport.<>c__DisplayClass2.b__1(RabbitMqConnection connect
ion) in d:\BuildAgent-02\work\8d1373c869590c5b\src\Transports\MassTransit.Transports.RabbitMq\OutboundRabbitMqTransport.
cs:line 51
at MassTransit.Transports.ConnectionHandlerImpl`1.<>c__DisplayClass3.b__2() in d:\BuildAgent-02\work\8d1373c8695
90c5b\src\MassTransit\Transports\ConnectionHandlerImpl.cs:line 81
at MassTransit.Transports.DefaultConnectionPolicy.Execute(Action callback) in d:\BuildAgent-02\work\8d1373c869590c5b\
src\MassTransit\Transports\DefaultConnectionPolicy.cs:line 34
at MassTransit.Transports.ConnectionPolicyChainImpl.Next(Action callback) in d:\BuildAgent-02\work\8d1373c869590c5b\s
rc\MassTransit\Transports\ConnectionPolicyChainImpl.cs:line 49
at MassTransit.Transports.ConnectOnFirstUsePolicy.Execute(Action callback) in d:\BuildAgent-02\work\8d1373c869590c5b\
src\MassTransit\Transports\ConnectOnFirstUsePolicy.cs:line 34
at MassTransit.Transports.ConnectionPolicyChainImpl.Next(Action callback) in d:\BuildAgent-02\work\8d1373c869590c5b\s
rc\MassTransit\Transports\ConnectionPolicyChainImpl.cs:line 49
at MassTransit.Transports.ConnectionPolicyChainImpl.Execute(Action callback) in d:\BuildAgent-02\work\8d1373c869590c5
b\src\MassTransit\Transports\ConnectionPolicyChainImpl.cs:line 54
at MassTransit.Transports.ConnectionHandlerImpl`1.Use(Action`1 callback) in d:\BuildAgent-02\work\8d1373c869590c5b\sr
c\MassTransit\Transports\ConnectionHandlerImpl.cs:line 81
at MassTransit.Transports.RabbitMq.OutboundRabbitMqTransport.Send(ISendContext context) in d:\BuildAgent-02\work\8d13
73c869590c5b\src\Transports\MassTransit.Transports.RabbitMq\OutboundRabbitMqTransport.cs:line 47
at MassTransit.Transports.Transport.Send(ISendContext context) in d:\BuildAgent-02\work\8d1373c869590c5b\src\MassTran
sit\Transports\Transport.cs:line 51
at MassTransit.Transports.Endpoint.Send[T](ISendContext`1 context) in d:\BuildAgent-02\work\8d1373c869590c5b\src\Mass
Transit\Transports\Endpoint.cs:line 79
--- End of inner exception stack trace ---
at MassTransit.Transports.Endpoint.Send[T](ISendContext`1 context) in d:\BuildAgent-02\work\8d1373c869590c5b\src\Mass
Transit\Transports\Endpoint.cs:line 88
at MassTransit.SendExtensions.Send[T](IEndpoint endpoint, T message, Action`1 contextCallback) in d:\BuildAgent-02\wo
rk\8d1373c869590c5b\src\MassTransit\SendExtensions.cs:line 49
at MassTransit.Context.ReceiveContext.Respond[T](T message, Action`1 contextCallback) in d:\BuildAgent-02\work\8d1373
c869590c5b\src\MassTransit\Context\ReceiveContext.cs:line 178
at MassTransit.Context.ConsumeContext`1.Respond[T](T message, Action`1 contextCallback) in d:\BuildAgent-02\work\8d13
73c869590c5b\src\MassTransit\Context\ConsumeContext.cs:line 161
at MassTransit.MessageContextExtensions.Respond[T](IConsumeContext context, T message) in d:\BuildAgent-02\work\8d137
3c869590c5b\src\MassTransit\Context\MessageContextExtensions.cs:line 100
at PingServer.PingHandler.<>c__DisplayClass1.b__0(IConsumeContext x) in D:\code\throw-away\PingServer\PingSe
rver\Program.cs:line 89
at MassTransit.Context.ContextStorage.Context(Action`1 contextCallback) in d:\BuildAgent-02\work\8d1373c869590c5b\src
\MassTransit\Context\ContextStorage.cs:line 102
at MassTransit.ContextExtensions.Context(IServiceBus bus, Action`1 contextCallback) in d:\BuildAgent-02\work\8d1373c8
69590c5b\src\MassTransit\Context\ContextExtensions.cs:line 44
at PingServer.PingHandler.Consume(Ping message) in D:\code\throw-away\PingServer\PingServer\Program.cs:line 89
at MassTransit.Pipeline.Sinks.ConsumerMessageSink`2.<>c__DisplayClass1.b__0(IConsumeContext`1 context) in d
:\BuildAgent-02\work\8d1373c869590c5b\src\MassTransit\Pipeline\Sinks\ConsumerMessageSink.cs:line 55
at MassTransit.Pipeline.Sinks.InboundConvertMessageSink`1.<>c__DisplayClass2.<>c__DisplayClass4.b__1(ICons
umeContext x) in d:\BuildAgent-02\work\8d1373c869590c5b\src\MassTransit\Pipeline\Sinks\InboundConvertMessageSink.cs:line
```

Repro:
Start the PongService. Terminate it without allowing it to shutdown properly.
Start it again directly afterwards, before RMQ has decided the old connection to be dead.
Null ref ex.

Expected behaviour:
First of all; exponential-backoff + logging of this from trying to connect, or something like circuit breaker pattern.
If, after some configurable connection timeout it still won't connect, a typed exception that it cannot connect.