You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When we use MQTTnet.Server's method WithEncryptedEndpointBoundIPAddress(), the port does not get opened. No error is generated. It just fails silently.
All things kept equal, WithDefaultEndpointBoundIPAddress() works as expected. We're currently using WithEncryptedEndpoint() as a work-around.
Which project is your bug related to?
Server
To Reproduce
Windows 10, C#, .NET Standard 2.0, MQTTnet v3.0.13 (also reproduced with latest stable v3.0.16)
Configure UseEncryption to true and the BrokerAddress to a valid local IPv4 address (see code below).
Note that there are no logged traces or errors
Check for connection using netstat
Note that the connection does not appear to have been created.
FYI: I noticed in the opensource code that the property TreatSocketOpeningErrorAsWarning was set to true in the MqttServerService constructor. I set this to false and rebuilt it (then updated the MQTTnet in my project). Still the same result.
Expected behavior
An error should be generated or the connection should be created.
Code example
For reference, here's the code that we were using:
/// <summary>/// Initialize the broker to receive subscriptions and publications./// </summary>publicvoidInitialize(){// We configure the broker to accept all connections, all subscriptions, all publications, and to use the default endpoint. We set the port and IP address to their default values.MqttServerOptionsBuilderoptionsBuilder=new MqttServerOptionsBuilder().WithConnectionValidator(this).WithDisconnectedInterceptor(this)// No longer available in 3.0.16.WithSubscriptionInterceptor(this).WithUnsubscriptionInterceptor(this).WithApplicationMessageInterceptor(this);// Configure endpoints for either encrypted or unencrypted communication.if(m_configuration.UseEncryption){// Find the server certificate in the current user certificate storeX509Certificate2brokerCertificate=null;try{X509StoreuserStore=new X509Store(StoreName.My);
userStore.Open(OpenFlags.OpenExistingOnly);X509Certificate2Collectioncertificates= userStore.Certificates.Find(X509FindType.FindByThumbprint, m_configuration.CertificateThumbprint, m_configuration.ValidateCertificate);if(certificates.Count >0){brokerCertificate= certificates[0];}
userStore.Close();}catch(Exceptionexception){
m_logger?.LogError(exception,"Cannot start broker (exception thrown while trying to retrieve the broker certificate from the certificate store)");}// Set options builderif(brokerCertificate!=null){
optionsBuilder.WithEncryptionCertificate(brokerCertificate.Export(X509ContentType.Pkcs12));
optionsBuilder.WithEncryptionSslProtocol(System.Security.Authentication.SslProtocols.Tls12);
optionsBuilder.WithEncryptedEndpointPort(m_configuration.BrokerPort);try{IPAddressaddress= IPAddress.Parse(m_configuration.BrokerAddress);
optionsBuilder.WithEncryptedEndpointBoundIPAddress(address);}catch(Exceptionexception){
optionsBuilder.WithDefaultEndpoint();
m_logger?.LogWarning(exception,$"Could not use configured broker address {m_configuration.BrokerAddress}. Will fall back to default endpoint.");}// Start broker_= m_mqttServer.StartAsync(optionsBuilder.Build());}else{
m_logger?.LogError("Cannot start broker (could not find broker certificate in certificate store)");}}else{
optionsBuilder.WithDefaultEndpointPort(m_configuration.BrokerPort);try{IPAddressaddress= IPAddress.Parse(m_configuration.BrokerAddress);
optionsBuilder.WithDefaultEndpointBoundIPAddress(address);}catch(Exceptionexception){
optionsBuilder.WithDefaultEndpoint();
m_logger?.LogWarning(exception,$"Could not use configured broker address {m_configuration.BrokerAddress}. Will fall back to default endpoint.");}// Start broker_= m_mqttServer.StartAsync(optionsBuilder.Build());}}
The text was updated successfully, but these errors were encountered:
Describe the bug
When we use MQTTnet.Server's method WithEncryptedEndpointBoundIPAddress(), the port does not get opened. No error is generated. It just fails silently.
All things kept equal, WithDefaultEndpointBoundIPAddress() works as expected. We're currently using WithEncryptedEndpoint() as a work-around.
Which project is your bug related to?
To Reproduce
FYI: I noticed in the opensource code that the property TreatSocketOpeningErrorAsWarning was set to true in the MqttServerService constructor. I set this to false and rebuilt it (then updated the MQTTnet in my project). Still the same result.
Expected behavior
An error should be generated or the connection should be created.
Code example
For reference, here's the code that we were using:
The text was updated successfully, but these errors were encountered: