The initial state of MqttConnectionHandler can result in a NullReferenceException in the time between generic host starup and "full" startup. In my test environment this occurs consistently. For a workaround, I explicitly pull and inject the dependencies by calling StartAsync after building and prior to starting the host.
As I understand it, the connection should be terminated rather than remain unhandled in an invalid state.
public override async Task OnConnectedAsync(ConnectionContext connection)
{
...
var clientHandler = ClientHandler;
if (clientHandler != null)
{
await clientHandler(adapter).ConfigureAwait(false);
}
+ else
+ {
+ connection.Abort();
+ }
}
Initially called out by @xljiulang in #2102 (comment)
Edited for clarity and to sync up to current master
The initial state of
MqttConnectionHandlercan result in aNullReferenceExceptionin the time between generic host starup and "full" startup. In my test environment this occurs consistently. For a workaround, I explicitly pull and inject the dependencies by callingStartAsyncafter building and prior to starting the host.As I understand it, the connection should be terminated rather than remain unhandled in an invalid state.
public override async Task OnConnectedAsync(ConnectionContext connection) { ... var clientHandler = ClientHandler; if (clientHandler != null) { await clientHandler(adapter).ConfigureAwait(false); } + else + { + connection.Abort(); + } }Initially called out by @xljiulang in #2102 (comment)
Edited for clarity and to sync up to current master