mqttnet 3.1.1 Qos 2 issue
- Dominant language
- C#
- Stars
- 5.1k
- Forks
- 1.2k
- PR merge metrics
- No merged PRs in 30d
Description
**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.**
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.