Explorar el Código

Process all queued message before server stops (#1234)

* process all queued message befor server stops

* fix an issue

Co-authored-by: ablfzl <ablfzl21@outlook.com>
release/3.x.x
Ablfzl Edgelolli hace 3 años
committed by GitHub
padre
commit
dd0aba0640
No se encontró ninguna clave conocida en la base de datos para esta firma ID de clave GPG: 4AEE18F83AFDEB23
Se han modificado 1 ficheros con 7 adiciones y 11 borrados
  1. +7
    -11
      Source/MQTTnet/Server/Internal/MqttClientSessionsManager.cs

+ 7
- 11
Source/MQTTnet/Server/Internal/MqttClientSessionsManager.cs Ver fichero

@@ -80,7 +80,7 @@ namespace MQTTnet.Server.Internal
_logger.Warning("Client '{0}': First received packet was no 'CONNECT' packet [MQTT-3.1.0-1].", channelAdapter.Endpoint);
return null;
}
public async Task HandleClientConnectionAsync(IMqttChannelAdapter channelAdapter, CancellationToken cancellationToken)
{
MqttClientConnection clientConnection = null;
@@ -95,7 +95,7 @@ namespace MQTTnet.Server.Internal
}

MqttConnAckPacket connAckPacket;
var connectionValidatorContext = await ValidateConnection(connectPacket, channelAdapter).ConfigureAwait(false);
if (connectionValidatorContext.ReasonCode != MqttConnectReasonCode.Success)
{
@@ -272,11 +272,12 @@ namespace MQTTnet.Server.Internal

async Task TryProcessQueuedApplicationMessagesAsync(CancellationToken cancellationToken)
{
while (!cancellationToken.IsCancellationRequested)
//make sure all queued messages are proccessed befor server stops
while (!cancellationToken.IsCancellationRequested || _messageQueue.Any())
{
try
{
await TryProcessNextQueuedApplicationMessageAsync(cancellationToken).ConfigureAwait(false);
await TryProcessNextQueuedApplicationMessageAsync().ConfigureAwait(false);
}
catch (OperationCanceledException)
{
@@ -288,16 +289,14 @@ namespace MQTTnet.Server.Internal
}
}

async Task TryProcessNextQueuedApplicationMessageAsync(CancellationToken cancellationToken)
async Task TryProcessNextQueuedApplicationMessageAsync()
{
try
{
cancellationToken.ThrowIfCancellationRequested();

MqttPendingApplicationMessage queuedApplicationMessage;
try
{
queuedApplicationMessage = _messageQueue.Take(cancellationToken);
queuedApplicationMessage = _messageQueue.Take();
}
catch (ArgumentNullException)
{
@@ -370,9 +369,6 @@ namespace MQTTnet.Server.Internal
await InterceptApplicationMessageAsync(undeliveredMessageInterceptor, clientConnection, applicationMessage).ConfigureAwait(false);
}
}
catch (OperationCanceledException)
{
}
catch (Exception exception)
{
_logger.Error(exception, "Unhandled exception while processing next queued application message.");


Cargando…
Cancelar
Guardar