MQTTnet is a high performance .NET library for MQTT based communication. It provides a MQTT client and a MQTT server (broker). The implementation is based on the documentation from http://mqtt.org/.
MIT License
4.51k
stars
1.07k
forks
source link
Issue using MqttClientConnectionContextFactory because of bug in MqttConnectionContext #1818
Describe the bug
When creating a client connection using
MqttClientConnectionContextFactory
in an AspNetCore project, an error is thrown and the client does not connect. MqttClientConnectionContextFactory passes aTcpConnection
object toMqttConnectionContext
for theConnectionContext
parameter in the constructor. The constructor tries to store theconnection.Transport.Input
andconnection.Transport.Output
into local fields, howeverconnection.Transport
is null becauseStartAsync
onTcpConnection
has not yet been called. https://github.com/dotnet/MQTTnet/blob/b1dc8607af12c2ec6e2e27ab843f315676c82681/Source/MQTTnet.AspnetCore/MqttConnectionContext.cs#L36-L37 There is code inConnectAsync
that is meant to address this, but the code never gets there since the constructor throws an NRE. https://github.com/dotnet/MQTTnet/blob/b1dc8607af12c2ec6e2e27ab843f315676c82681/Source/MQTTnet.AspnetCore/MqttConnectionContext.cs#L109-L118Which component is your bug related to?
To Reproduce
Steps to reproduce the behavior:
Expected behavior
It should not throw and error. The transport properties should be initialized in only one place under ConnectAsync.