1742 some bug in mqttclientconnectionvalidatorhandle (#1746)

This commit is contained in:
Christian
2023-05-29 13:53:42 +02:00
committed by GitHub
parent 66b77f8d6d
commit caa717544b
3 changed files with 18 additions and 22 deletions
+1
View File
@@ -8,4 +8,5 @@
* [Client] Exposed more TLS options (#1729). * [Client] Exposed more TLS options (#1729).
* [Client] Fixed wrong return code conversion (#1729). * [Client] Fixed wrong return code conversion (#1729).
* [Server] Improved performance by changing internal locking strategy for subscriptions (#1716, thanks to @zeheng). * [Server] Improved performance by changing internal locking strategy for subscriptions (#1716, thanks to @zeheng).
* [Server] Fixed exceptions when clients are connecting and disconnecting very fast while accessing the client status for connection validation (#1742).
* [Server] Exposed more properties in _ClientConnectedEventArgs_ (#1738). * [Server] Exposed more properties in _ClientConnectedEventArgs_ (#1738).
@@ -58,7 +58,7 @@ namespace MQTTnet.Server
_eventContainer = eventContainer ?? throw new ArgumentNullException(nameof(eventContainer)); _eventContainer = eventContainer ?? throw new ArgumentNullException(nameof(eventContainer));
} }
public async Task CloseAllConnectionsAsync() public async Task CloseAllConnections()
{ {
List<MqttClient> connections; List<MqttClient> connections;
lock (_clients) lock (_clients)
@@ -306,17 +306,17 @@ namespace MQTTnet.Server
} }
} }
public Task<IList<MqttClientStatus>> GetClientStatusesAsync() public Task<IList<MqttClientStatus>> GetClientsStatus()
{ {
var result = new List<MqttClientStatus>(); var result = new List<MqttClientStatus>();
lock (_clients) lock (_clients)
{ {
foreach (var connection in _clients.Values) foreach (var client in _clients.Values)
{ {
var clientStatus = new MqttClientStatus(connection) var clientStatus = new MqttClientStatus(client)
{ {
Session = new MqttSessionStatus(connection.Session) Session = new MqttSessionStatus(client.Session)
}; };
result.Add(clientStatus); result.Add(clientStatus);
@@ -326,7 +326,7 @@ namespace MQTTnet.Server
return Task.FromResult((IList<MqttClientStatus>)result); return Task.FromResult((IList<MqttClientStatus>)result);
} }
public Task<IList<MqttSessionStatus>> GetSessionStatusAsync() public Task<IList<MqttSessionStatus>> GetSessionsStatus()
{ {
var result = new List<MqttSessionStatus>(); var result = new List<MqttSessionStatus>();
@@ -614,20 +614,15 @@ namespace MQTTnet.Server
// Create a new client (always required). // Create a new client (always required).
lock (_clients) lock (_clients)
{ {
_clients.TryGetValue(connectPacket.ClientId, out oldClient); _clients.TryGetValue(connectPacket.ClientId, out oldClient);
} if (oldClient != null)
{
if (oldClient != null) // This will stop the current client from sending and receiving but remains the connection active
{ // for a later DISCONNECT packet.
// This will stop the current client from sending and receiving but remains the connection active oldClient.IsTakenOver = true;
// for a later DISCONNECT packet. }
oldClient.IsTakenOver = true;
}
client = CreateClient(connectPacket, channelAdapter, session); client = CreateClient(connectPacket, channelAdapter, session);
lock (_clients)
{
_clients[connectPacket.ClientId] = client; _clients[connectPacket.ClientId] = client;
} }
} }
+3 -3
View File
@@ -200,7 +200,7 @@ namespace MQTTnet.Server
{ {
ThrowIfNotStarted(); ThrowIfNotStarted();
return _clientSessionsManager.GetClientStatusesAsync(); return _clientSessionsManager.GetClientsStatus();
} }
public Task<IList<MqttApplicationMessage>> GetRetainedMessagesAsync() public Task<IList<MqttApplicationMessage>> GetRetainedMessagesAsync()
@@ -226,7 +226,7 @@ namespace MQTTnet.Server
{ {
ThrowIfNotStarted(); ThrowIfNotStarted();
return _clientSessionsManager.GetSessionStatusAsync(); return _clientSessionsManager.GetSessionsStatus();
} }
public Task InjectApplicationMessage(InjectedMqttApplicationMessage injectedApplicationMessage, CancellationToken cancellationToken = default) public Task InjectApplicationMessage(InjectedMqttApplicationMessage injectedApplicationMessage, CancellationToken cancellationToken = default)
@@ -292,7 +292,7 @@ namespace MQTTnet.Server
_cancellationTokenSource.Cancel(false); _cancellationTokenSource.Cancel(false);
await _clientSessionsManager.CloseAllConnectionsAsync().ConfigureAwait(false); await _clientSessionsManager.CloseAllConnections().ConfigureAwait(false);
foreach (var adapter in _adapters) foreach (var adapter in _adapters)
{ {