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

Clients do not receive disconnect signal #1411

Open
Fianax opened this issue May 12, 2022 · 5 comments
Open

Clients do not receive disconnect signal #1411

Fianax opened this issue May 12, 2022 · 5 comments
Labels
bug Something isn't working

Comments

@Fianax
Copy link

Fianax commented May 12, 2022

Describe the bug

Context:

I have a mosquitto server running in cmd on windows 10 and three mqtt clients in c# visual studio.

One of them (3) feeds the topics at 20 data per second (Qos 0 and retain). And the other two clients (1 and 2) feed on said data to make calculations and when they are finished, they publish them in different topics also at 20 data per second (Qos 0 and retain). In addition, they also publish information data only once per client execution (Qos 2 and retain).

'They have different ClientId'

Problem:

When I run one of the clients (1) and it starts to publish the calculated data + the information, nothing happens but if I run the other client (2) on the second, the first one stops publishing and receiving from the server.

I have been checking what is happening and the server says "client has exceeded timeout disconnecting" but the disconnect callback is not called and the affected client is not notified (2) but the property client.IsConnect == false.

No matter how much I do Client.StopAsync() and then Client.StartAsync(options), it won't reconnect unless I do new client = new MqttFactory().CreateManagedMqttClient()

Thanks for your time.

Which component is your bug related to?

  • Client
  • ManagedClient

To Reproduce

To reproduce it, create a small app that sends +30 topics information (20 data per second) with mqttnet to a mosquitto server executed from a cmd and the following .conf

Create two clients that while they feed on this data, make calculations with them (any simple calculation would do) and publish them in other topics at 20 data per second (the publication topics are unique for each client, although I think it does not affect the error ).

Start one of them and the second starts the other and you will see the error (at the same time it also fails)

Expected behavior

I expected normal operation, that they would not be disconnected because another client would also publish to the server (in different topics and running on different machines).
Also misses with just one, but rarer.

Screenshots

Additional context / logging

I think the error is in the publish.

Client = new MqttFactory().CreateManagedMqttClient();
Callbacks();
var options = new ManagedMqttClientOptions
            {
                //AutoReconnectDelay = TimeSpan.FromSeconds(1),
                PendingMessagesOverflowStrategy = MqttPendingMessagesOverflowStrategy.DropOldestQueuedMessage,
                ClientOptions = new MqttClientOptions()
                {
                    ClientId = "BBBBBB",//Guid.NewGuid().ToString("N"),
                    ChannelOptions = new MqttClientTcpOptions()
                    {
                        Server = "127.0.0.1",
                        Port = "1890"
                    },
                    Credentials = new MqttClientCredentials()
                    {
                        Username = "prueba",
                        Password = Encoding.ASCII.GetBytes("prueba"),
                    },
                    KeepAlivePeriod = TimeSpan.FromSeconds(5),
                    ProtocolVersion = MQTTnet.Formatter.MqttProtocolVersion.V500,
                    CleanSession = true, 
                }
           };
try
{
    await Client.StartAsync(options);
}
catch(Exception e){
    Debug.WriteLine(e);
}
private void Callbacks()
        {
            Client.ApplicationMessageReceivedAsync += MessageReceived;
            Client.ConnectedHandler = new MqttClientConnectedHandlerDelegate(async context => { await Connected(context); });
            Client.DisconnectedHandler = new MqttClientDisconnectedHandlerDelegate(async context => { await Disconnected(context); });
            Client.SynchronizingSubscriptionsFailedHandler = new SynchronizingSubscriptionsFailedHandlerDelegate(context =>
            {
                Debug.WriteLine("EEEEEEEEEEEE");
            });
            Client.ConnectingFailedHandler = new ConnectingFailedHandlerDelegate(async context =>
            {
                Debug.WriteLine("RRRRRRRRRRRRRRRRRRRR " + " --- " + Client.IsConnected);
            });
        }

.CONF server mosquitto

allow_anonymous false
password_file passwordfile.pwd
acl_file acl.acl
listener 1890
connection_messages true
max_inflight_messages 0
max_connections -1
max_topic_alias 100
max_queued_messages 10000
max_queued_bytes 0
queue_qos0_messages false
set_tcp_nodelay true

@Fianax Fianax added the bug Something isn't working label May 12, 2022
@chkr1011
Copy link
Collaborator

Please test this with version 4 preview from the MyGet feed and let me know if the issue still exists?

@Fianax
Copy link
Author

Fianax commented May 17, 2022

I use Visual Studio (nuget package), which one is it?

4.0.0.0-preview4 or 4.0.0.0-preview5

@cosme-mp
Copy link

I have tried the latest version of nuget and it also fails (after modifying the code I had to version 4)

However, with the System.Net.Mqtt package I don't get this error (it gives me another error that mqttnet doesn't have hahaha), doing the same thing with both packages.

I hope you can help me.

Thank you :)

@chkr1011
Copy link
Collaborator

chkr1011 commented Jun 4, 2022

Are you using a different client ID for each client? What exactly is the exception from the other MQTT client library?

@Fianax
Copy link
Author

Fianax commented Jun 10, 2022

Hello, sorry for the wait.

Yes, I confirm and reconfirm that the clientIDs are different. It was the first thing I checked because it had happened to me before.

No exception is thrown, I simply stop receiving data but the disconnect event does not occur when in the CMD where I run mosquitto it tells me "client disconnect xxxxxxxx timeout"

In both Mqttnet and System.net.mqtt it happens.

In mqttnet it fails more, however in system.net.mqtt it is more sporadic but from time to time it happens

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

3 participants