Skip to content

Bug when reconnecting to MQTT #1692

@ababere

Description

@ababere

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions