From ba575371088b3a9a21f2391642a9917343dccdc9 Mon Sep 17 00:00:00 2001 From: Christian <6939810+chkr1011@users.noreply.github.com> Date: Fri, 17 Feb 2023 21:17:31 +0100 Subject: [PATCH] Fix running state handling in server (#1680) Fix running state handling --- .github/workflows/ReleaseNotes.md | 1 + Source/MQTTnet/Server/Internal/MqttClient.cs | 5 ++--- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ReleaseNotes.md b/.github/workflows/ReleaseNotes.md index e3f4597d..baf6356e 100644 --- a/.github/workflows/ReleaseNotes.md +++ b/.github/workflows/ReleaseNotes.md @@ -10,3 +10,4 @@ * [Server] Added support for changing the used TLS certificate while the server is running (#1652, thanks to @YAJeff). The certificate provider will now be invoked for every new connection! * [Server] Added a new API method which allows reading a single retained message without the need to processing the entire set of retained messages (#1659). * [Server] Added a new event (InterceptingClientEnqueueAsync) which allows intercepting when an application message is enqueued for a client (#1648). +* [Server] Fixed race condition when handling connections which leads to stopped message transfers (#1677, thanks to @RazvanEmilR). diff --git a/Source/MQTTnet/Server/Internal/MqttClient.cs b/Source/MQTTnet/Server/Internal/MqttClient.cs index 97895676..53b49fdc 100644 --- a/Source/MQTTnet/Server/Internal/MqttClient.cs +++ b/Source/MQTTnet/Server/Internal/MqttClient.cs @@ -94,10 +94,9 @@ namespace MQTTnet.Server try { var cancellationToken = _cancellationToken.Token; - - _ = Task.Factory.StartNew(() => SendPacketsLoop(cancellationToken), cancellationToken, TaskCreationOptions.PreferFairness, TaskScheduler.Default).ConfigureAwait(false); - IsRunning = true; + + _ = Task.Factory.StartNew(() => SendPacketsLoop(cancellationToken), cancellationToken, TaskCreationOptions.PreferFairness, TaskScheduler.Default).ConfigureAwait(false); await ReceivePackagesLoop(cancellationToken).ConfigureAwait(false); }