Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connection timeout error due to high latency on the network #1956

Open
osmanhadzic opened this issue Mar 22, 2024 · 0 comments
Open

Connection timeout error due to high latency on the network #1956

osmanhadzic opened this issue Mar 22, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@osmanhadzic
Copy link

I try to create a strategy for the fallout messages. When the client loses connection, messages are saved to the local database. After reconnecting the device on the VerneMQ broker, the device resends messages to the VerneMQ broker.

Suppose we have a network with latency of 10 second. I configured latency via:
sudo tc qdisc add dev lo root netem delay 10s
When I call ConnectAsync method, I get an OperationCanceledException exception.

The example below shows I use ConnectAsync with cancelation token. I have also used:

MqttClientOptionsBuilder()
...
.WithTimeout(20000ms) 
...
.Build()
try
            {
                using (var timeoutToken = new CancellationTokenSource(20000))
                {
                    MqttClientConnectResult result = await _client.ConnectAsync(
                    _connectionInfo.GetMqttConnectOptions(),
                    timeoutToken.Token);

                    if (result.ResultCode == MqttClientConnectResultCode.Success)
                    {
                        await CompleteAstarteConnection(result.IsSessionPresent);
                    }
                    else
                    {
                        throw new AstarteTransportException
                        ($"Error connecting to MQTT. Code: {result.ResultCode}");
                    }
                }
            }
            catch (OperationCanceledException)
            {
                Trace.WriteLine("Timeout while connecting.");
            }
@osmanhadzic osmanhadzic added the bug Something isn't working label Mar 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant