Skip to content

mqttnet 3.1.1 Qos 2 issue #2145

@ree-g-dass

Description

@ree-g-dass

An error occurred: Received packet 'PubAck: [PacketIdentifier=1] [ReasonCode=]' at an unexpected time.
I am facing the same issue, only secific to QOS2. Mqttnet 3.1.1, in C#.

var clientOptions = new MqttClientOptionsBuilder()
.WithTcpServer("test",8883) // Broker host and TLS secure post transfer
.WithCredentials("id", "pwd") // Username and password
.WithClientId("id")
.WithTls(new MqttClientOptionsBuilderTlsParameters
{
UseTls = true,
AllowUntrustedCertificates = true, // Set to false in production
IgnoreCertificateChainErrors = true, // Set to false in production
IgnoreCertificateRevocationErrors = true // Set to false in production
})
.WithCleanSession(false) // Clean session false
.WithCommunicationTimeout(TimeSpan.FromSeconds(10000))
.WithKeepAlivePeriod(TimeSpan.FromSeconds(1000))
.WithProtocolVersion(MQTTnet.Formatter.MqttProtocolVersion.V311)
.Build();

Payload: var

mqttMessage = new MqttApplicationMessageBuilder()
.WithTopic("") // Topic
.WithPayload(Encoding.UTF8.GetBytes(serializedMessage)) // JSON Payload
.WithQualityOfServiceLevel(MqttQualityOfServiceLevel.ExactlyOnce) //Qos2 exactly once
.WithRetainFlag()
.Build();

ERROR:

File Read successfully!!
Connecting to MQTT broker...
Connected to MQTT broker.
Connected to MQTT broker successfully.
**An error occurred: Received packet 'PubAck: [PacketIdentifier=1] [ReasonCode=]' at an unexpected time.**
Disconnected from MQTT broker.

The code works fine without await: mqttClient.PublishAsync(mqttMessage); when i use: await mqttClient.PublishAsync(mqttMessage);, it fails with the above error. Do you have any suggestions? @chkr1011 ( is await mandatory for publish?, what could be the potential consequences if i dont use it?)

I tried this based on another issue reference:

var properties = mqttClient.PublishAsync(mqttMessage);
await Task.WhenAll(properties);

Still the same issue. An error occurred: Received packet 'PubAck: [PacketIdentifier=1] [ReasonCode=]' at an unexpected time.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions