Incorrect server behavior with persistent session (one message is missing)
- Dominant language
- C#
- Stars
- 5.1k
- Forks
- 1.2k
- PR merge metrics
- No merged PRs in 30d
Description
### Describe the bug
MQTTnet based server (ASP.NET 6)
Two clients based on the ManagedMqttClient.
Both connected with persisted session on WS.
Client 1 publishes messages on topic2 with QoS of 2.
Client 2 subscribed to messages on topic2 with QoS of 2.
Stopping network of Client 2.
Waiting for 5-10 sec.
Enabling network of Client 2.
Client 2 is reconnected shortly.
Client 2 receives all the missed messages from Client 1, but the first one.
Same scenario works fine with Mosquito test broker (ws://test.mosquitto.org:8080/)
Version used (MQTTnet) 4.2.1.781
### Which component is your bug related to?
- Server
### To Reproduce
Steps to reproduce the behavior:
1. Start MQTTnet broker with WS and persistent session support.
2. Start managed Client 1 and connect with persistent session to the broker (clientId1).
3. Start managed Client 2 and connect with persistent session to the broker (clientId2).
4. Subscribe Client 2 to messages with topic2 and QoS of 2. Preferably on VM (or another machine).
5. Start sending messages on every second from Client 1 to topic2 with QoS of 2 .
6. Messages should contain some unique identifier like id, number, timestamp, etc.
7. Disable Client 2's machine NIC.
8. Wait 5 - 10 seconds.
9. Enable Client 2's machine NIC.
10. Wait Client 2 to automatically reconnect.
11. Wait to receive the missed messages from Client 1.
12. Examine the received messages. One of them is missing. Actually this should be the first one send by Client 1 at the moment after Client 2's machine NIC has been disabled.
### Expected behavior
All the messages are received.
### Screenshots
No screenshots
### Additional context / logging
It is interesting, that if Client 2 performs Disconnect and Connect (via ManagedMqttClient), the missed message is received.
Also in reported steps, if disable and enable NIC (7 and 9) are replaced with disconnect and connect - all the messages are received. So issue happens only if network/connection is forcibly closed from outside. But them message stays somewhere in the server.
```batch
\\ Put your logging output here.
```
### Code example
Please provide full code examples below where possible to make it easier for the developers to check your issues.
**Ideally a Unit Test (which shows the error) is provided so that the behavior can be reproduced easily.**
```csharp
\\ Put your code here.
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reproducing the reported scenario with an MQTTnet server using WebSockets and persistent sessions, two ManagedMqttClient clients, and QoS 2 messages. Disable Client 2's network, wait 5–10 seconds, reconnect it, and compare the received identifiers with those sent. Done means every missed message, including the first sent after disconnection, is received; compare this with an explicit disconnect and reconnect.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- backend, networking
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100