Home icon indicating copy to clipboard operation
Home copied to clipboard

Bug when reconnecting to MQTT

Open ababere opened this issue 3 months ago • 0 comments

Library/API/IoT binding

nanoFramework.M2Mqtt

Visual Studio version

VS2026

.NET nanoFramework extension version

No response

Target name(s)

Freenove ESP32-S3

Firmware version

No response

Device capabilities

No response

Description

If, after connecting to the MQT broker, the network is interrupted or the MQTT broker stops working, the socket hangs and the program stops responding to requests.

In the nanoFramework.M2Mqtt MqttClient.cs library (line 1653), the connection is closed and an attempt is made to access the socket.

                    if ((_eventQueue.Count == 0) && _isConnectionClosing)
                    {
                        // client must close connection
                        Close();

                        // client raw disconnection
                        OnConnectionClosed();
                    }

However, at this point, in the MqttNetworkChannel.cs, line 152, the creation and connection are called.

            _socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            // try connection to the broker
            _socket.Connect(new IPEndPoint(_remoteIpAddress, _remotePort));

and the program hangs. No exceptions are raised.

The goal is to endlessly attempt to connect to the MQTT broker.

How to reproduce

No response

Expected behaviour

No response

Screenshots

No response

Sample project or code

No response

Aditional information

No response

ababere avatar Nov 13 '25 09:11 ababere