mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-20 19:58:57 +08:00
Disallow to call MqttClient.ConnectAsync while Disconnect is pending.
Fix #996 Fix #1010
This commit is contained in:
@@ -71,6 +71,9 @@ namespace MQTTnet.Client
|
|||||||
|
|
||||||
ThrowIfDisposed();
|
ThrowIfDisposed();
|
||||||
|
|
||||||
|
if (Volatile.Read(ref _isDisconnectPending) != 0)
|
||||||
|
throw new InvalidOperationException("Not allowed to connect while disconnect is pending.");
|
||||||
|
|
||||||
MqttClientAuthenticateResult authenticateResult = null;
|
MqttClientAuthenticateResult authenticateResult = null;
|
||||||
|
|
||||||
try
|
try
|
||||||
@@ -83,7 +86,6 @@ namespace MQTTnet.Client
|
|||||||
_backgroundCancellationTokenSource = new CancellationTokenSource();
|
_backgroundCancellationTokenSource = new CancellationTokenSource();
|
||||||
var backgroundCancellationToken = _backgroundCancellationTokenSource.Token;
|
var backgroundCancellationToken = _backgroundCancellationTokenSource.Token;
|
||||||
|
|
||||||
_isDisconnectPending = 0;
|
|
||||||
var adapter = _adapterFactory.CreateClientAdapter(options);
|
var adapter = _adapterFactory.CreateClientAdapter(options);
|
||||||
_adapter = adapter;
|
_adapter = adapter;
|
||||||
|
|
||||||
@@ -357,6 +359,7 @@ namespace MQTTnet.Client
|
|||||||
{
|
{
|
||||||
Cleanup();
|
Cleanup();
|
||||||
_cleanDisconnectInitiated = false;
|
_cleanDisconnectInitiated = false;
|
||||||
|
Volatile.Write(ref _isDisconnectPending, 0);
|
||||||
|
|
||||||
_logger.Info("Disconnected.");
|
_logger.Info("Disconnected.");
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user