Browse Source

Fix an issue which adds a delay after every accepted connection.

release/3.x.x
Christian 7 years ago
parent
commit
8773117493
1 changed files with 4 additions and 20 deletions
  1. +4
    -20
      Frameworks/MQTTnet.NetStandard/Implementations/MqttServerAdapter.cs

+ 4
- 20
Frameworks/MQTTnet.NetStandard/Implementations/MqttServerAdapter.cs View File

@@ -110,22 +110,14 @@ namespace MQTTnet.Implementations
{ {
// It can happen that the listener socket is accessed after the cancellation token is already set and the listener socket is disposed. // It can happen that the listener socket is accessed after the cancellation token is already set and the listener socket is disposed.
} }
catch (SocketException exception)
catch (Exception exception)
{ {
if (exception.SocketErrorCode == SocketError.OperationAborted)
if (exception is SocketException s && s.SocketErrorCode == SocketError.OperationAborted)
{ {
return; return;
} }


_logger.Error<MqttServerAdapter>(exception, "Error while accepting connection at default endpoint."); _logger.Error<MqttServerAdapter>(exception, "Error while accepting connection at default endpoint.");
}
catch (Exception exception)
{
_logger.Error<MqttServerAdapter>(exception, "Error while accepting connection at default endpoint.");
}
finally
{
//excessive CPU consumed if in endless loop of socket errors
await Task.Delay(TimeSpan.FromSeconds(1), cancellationToken).ConfigureAwait(false); await Task.Delay(TimeSpan.FromSeconds(1), cancellationToken).ConfigureAwait(false);
} }
} }
@@ -153,22 +145,14 @@ namespace MQTTnet.Implementations
{ {
// It can happen that the listener socket is accessed after the cancellation token is already set and the listener socket is disposed. // It can happen that the listener socket is accessed after the cancellation token is already set and the listener socket is disposed.
} }
catch (SocketException exception)
catch (Exception exception)
{ {
if (exception.SocketErrorCode == SocketError.OperationAborted)
if (exception is SocketException s && s.SocketErrorCode == SocketError.OperationAborted)
{ {
return; return;
} }


_logger.Error<MqttServerAdapter>(exception, "Error while accepting connection at default endpoint.");
}
catch (Exception exception)
{
_logger.Error<MqttServerAdapter>(exception, "Error while accepting connection at TLS endpoint."); _logger.Error<MqttServerAdapter>(exception, "Error while accepting connection at TLS endpoint.");
}
finally
{
//excessive CPU consumed if in endless loop of socket errors
await Task.Delay(TimeSpan.FromSeconds(1), cancellationToken).ConfigureAwait(false); await Task.Delay(TimeSpan.FromSeconds(1), cancellationToken).ConfigureAwait(false);
} }
} }


Loading…
Cancel
Save