mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-20 19:58:57 +08:00
Fix exception handling when using invalid host names upon connect.
This commit is contained in:
@@ -17,6 +17,7 @@
|
|||||||
* [Client] Added method to trigger PING/PONG manually (connection check etc.).
|
* [Client] Added method to trigger PING/PONG manually (connection check etc.).
|
||||||
* [Client] Added support for certificate validation callback when using Web Sockets (requires netstandard2.1+).
|
* [Client] Added support for certificate validation callback when using Web Sockets (requires netstandard2.1+).
|
||||||
* [Client] Fixed a memory leak when web socket based connections trying to reconnect with an offline server.
|
* [Client] Fixed a memory leak when web socket based connections trying to reconnect with an offline server.
|
||||||
|
* [Client] Fixed an issue when connecting to an invalid host (format).
|
||||||
* [ManagedClient] Added method to trigger PING/PONG manually (connection check etc.).
|
* [ManagedClient] Added method to trigger PING/PONG manually (connection check etc.).
|
||||||
* [MQTTnet.AspNetCore] improved compatibility with AspNetCore 3.1.
|
* [MQTTnet.AspNetCore] improved compatibility with AspNetCore 3.1.
|
||||||
* [MQTTnet.AspNetCore] Fixed a packaging issue with the Nuget package.
|
* [MQTTnet.AspNetCore] Fixed a packaging issue with the Nuget package.
|
||||||
|
|||||||
@@ -333,7 +333,7 @@ namespace MQTTnet.Client
|
|||||||
|
|
||||||
await Task.WhenAll(receiverTask, publishPacketReceiverTask, keepAliveTask).ConfigureAwait(false);
|
await Task.WhenAll(receiverTask, publishPacketReceiverTask, keepAliveTask).ConfigureAwait(false);
|
||||||
|
|
||||||
_publishPacketReceiverQueue.Dispose();
|
_publishPacketReceiverQueue?.Dispose();
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -71,6 +71,8 @@ namespace MQTTnet.Implementations
|
|||||||
|
|
||||||
await socket.ConnectAsync(_options.Server, _options.GetPort(), cancellationToken).ConfigureAwait(false);
|
await socket.ConnectAsync(_options.Server, _options.GetPort(), cancellationToken).ConfigureAwait(false);
|
||||||
|
|
||||||
|
cancellationToken.ThrowIfCancellationRequested();
|
||||||
|
|
||||||
var networkStream = socket.GetStream();
|
var networkStream = socket.GetStream();
|
||||||
|
|
||||||
if (_options.TlsOptions?.UseTls == true)
|
if (_options.TlsOptions?.UseTls == true)
|
||||||
|
|||||||
@@ -23,6 +23,30 @@ namespace MQTTnet.Tests
|
|||||||
{
|
{
|
||||||
public TestContext TestContext { get; set; }
|
public TestContext TestContext { get; set; }
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
[ExpectedException(typeof(MqttCommunicationTimedOutException))]
|
||||||
|
public async Task Connect_To_Invalid_Server_Wrong_IP()
|
||||||
|
{
|
||||||
|
var client = new MqttFactory().CreateMqttClient();
|
||||||
|
await client.ConnectAsync(new MqttClientOptionsBuilder().WithTcpServer("1.2.3.4").WithCommunicationTimeout(TimeSpan.FromSeconds(2)).Build());
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
[ExpectedException(typeof(MqttCommunicationException))]
|
||||||
|
public async Task Connect_To_Invalid_Server_Port_Not_Opened()
|
||||||
|
{
|
||||||
|
var client = new MqttFactory().CreateMqttClient();
|
||||||
|
await client.ConnectAsync(new MqttClientOptionsBuilder().WithTcpServer("127.0.0.1", 12345).WithCommunicationTimeout(TimeSpan.FromSeconds(2)).Build());
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
[ExpectedException(typeof(MqttCommunicationException))]
|
||||||
|
public async Task Connect_To_Invalid_Server_Wrong_Protocol()
|
||||||
|
{
|
||||||
|
var client = new MqttFactory().CreateMqttClient();
|
||||||
|
await client.ConnectAsync(new MqttClientOptionsBuilder().WithTcpServer("http://127.0.0.1", 12345).WithCommunicationTimeout(TimeSpan.FromSeconds(2)).Build());
|
||||||
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public async Task Send_Manual_Ping()
|
public async Task Send_Manual_Ping()
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user