Skip to content

MQTTnet 4.3.3.952 - ClientId and Payload mismatch under high load #2203

@Kirubhashini07

Description

@Kirubhashini07

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");
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions