MqttClient Publish a message when you are inside the `InterceptingPublishAsync` result to an Error when the Client Publish a QoS 1
- Dominant language
- C#
- Stars
- 5.1k
- Forks
- 1.2k
- PR merge metrics
- No merged PRs in 30d
Description
Note: I'm migrating from version `3.1.2` to `4.3.3.952`
### Describe the bug
I have a device that is connecting to Mqtt,
The device is subscribing and publishing a message correctly.
But publishing a message from the server will be ignored if the PubAck is not sent.
Here is my setup,
I'm using the `InterceptingPublishAsync` event to intercept messages from the client.
In one of the messages I received, I would like to send another publish on a specific topic.
Unfortunately, the pubAck will be sent after my event inside the `InterceptingPublishAsync`
The Client will ignore the Message (The Device/Client is not using MQTTNET, but using a low-level library)
We can find the issue here:
https://github.com/dotnet/MQTTnet/blob/7f5c437c46dd52ecb1d53dfc8ea9fb8ff46caf5d/Source/MQTTnet/Server/Internal/MqttClient.cs#L218
Having another event after the end of a pubAck, will help handling the message. `OnCompletedPublishAsync`
### Description of the QoS 1 delivery protocol
> In the QoS 1 delivery protocol, the Sender
· MUST assign an unused Packet Identifier each time it has a new Application Message to publish.
· MUST send a PUBLISH Packet containing this Packet Identifier with QoS=1, DUP=0.
· MUST treat the PUBLISH Packet as “unacknowledged” until it has received the corresponding PUBACK packet from the receiver. See Section 4.4 for a discussion of unacknowledged messages.

1 The receiver is not required to complete delivery of the Application Message before sending the PUBACK. When its original sender receives the PUBACK packet, ownership of the Application Message is transferred to the receiver
### Which component is your bug related to?
- QoS 1 delivery protocol
- MqttClient
### To Reproduce
Steps to reproduce the behavior:
1. Using this version of MQTTnet '4.3.3.952'.
2. Subscribe to the server with `InterceptingPublishAsync`
3. Publish a message inside the event method
4. The Error can be seen with WireShark
### Expected behavior
The pubAck should be sent before I even handle the business logic of the event itself
### Screenshots
MqttNet 3

MqttNet 4

### Code example
```csharp
using MQTTnet;
using MQTTnet.Server;
var mqttFactory = new MqttFactory();
var mqttServerOptions = new MqttServerOptionsBuilder().WithDefaultEndpoint().Build();
using (var mqttServer = mqttFactory.CreateMqttServer(mqttServerOptions))
{
await mqttServer.StartAsync();
mqttServer.InterceptingPublishAsync += async (InterceptingPublishEventArgs arg) =>
{
// Create a new message using the builder as usual.
var message = new MqttApplicationMessageBuilder().WithTopic("HelloWorld").WithPayload("Test").Build();
// Now inject the new message at the broker.
await mqttServer.InjectApplicationMessage(
new InjectedMqttApplicationMessage(message)
{
SenderClientId = "SenderClientId"
});
};
Console.ReadLine();
// Stop and dispose the MQTT server if it is no longer needed!
await mqttServer.StopAsync();
}
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.