dotnet / dotnet/MQTTnet

MQTTnet 4.3.3.952 - ClientId and Payload mismatch under high load

Open
#2,203 6 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
C#
Stars
5.1k
Forks
1.2k
PR merge metrics
No merged PRs in 30d

Description

Hi, I am using MQTTnet (v4.5.9.2) to create a server (broker).I have multiple clients connecting with different ClientIds (e.g 0001, 0002, 0003 …).Each client sends a payload that contains its own ID.

Example:
ClientId = 0001 Topic = topic/msg payload = {0001, hello}
ClientId = 0002 Topic = topic/msg payload = {0002, hello}

Problem :
When I increase the number of clients (e.g 10 clients continuously publishing), sometimes I get a mismatch:
ClientId = 0002 Payload = {0003, hello}

This looks like an interrupt/overload issue, and the server receives the wrong combination of ClientId and payload.

Question :
Why does this mismatch happen?
How can I ensure that the payload always matches the ClientId?

Code:
public static async void ServerStart()
{
var options = new MqttServerOptionsBuilder()
.WithDefaultEndpointBoundIPAddress(IPAddress.Parse(ipstring))
.WithDefaultEndpoint()
.WithDefaultEndpointPort(80)
.WithConnectionBacklog(100);

var server = new MqttFactory().CreateMqttServer(options.Build());

server.ValidatingConnectionAsync += ValidatingConnection;

server.ClientConnectedAsync += Server_ClientConnectedAsync;

server.ClientDisconnectedAsync += Server_ClientDisconnectAsync;

server.InterceptingPublishAsync += Server_InterceptingPublishAsync;

await server.StartAsync(); // or server.StartAsync().GetAwaiter().GetResult();
}
static Task Server_ClientConnectedAsync(ClientConnectedEventArgs clientConnectedEventArgs)
{
Console.WriteLine(clientConnectedEventArgs.ClientId+ " Connected ");
return Task.CompletedTask;
}
static Task Server_InterceptingPublishAsync(InterceptingPublishEventArgs arg)
{
Client_Message = "ClientId : " + arg.ClientId + " Topic : " + arg.ApplicationMessage?.Topic + " Payload : " + arg.ApplicationMessage?.Payload == null ? null : Encoding.UTF8.GetString(arg.ApplicationMessage?.Payload) + time;
Console.WriteLine(Client_Message + "\n");
}

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the ServerStart method and Server_InterceptingPublishAsync handler shown in the report. Reproduce the mismatch with multiple clients publishing under load, then compare the event's ClientId and decoded payload to determine whether the problem is in MQTTnet or in the sample's logging and callback handling. Done means the cause is isolated and a verified resolution or documented limitation is provided.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
networking
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.