dotnet / dotnet/MQTTnet

Not receiving messages sent while disconnected with MqttProtocolVersion.V500

Open
#1,827 2 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
C#
Stars
5.1k
Forks
1.2k
PR merge metrics
No merged PRs in 30d

Description

### Describe the bug
Apologies if this is me misunderstanding something, or if this is actually a bug.

When testing behaviour of `.WithCleanSession(false)` I'm finding the client is not picking up messages that were sent while the client was previously offline. However if I change the protocol to V3.11 it works as expected.

### Which component is your bug related to?
- Client

### To Reproduce
Steps to reproduce the behavior:
1. Start client and connect with MqttProtocolVersion.V500
2. Send a test message, verify it shows on client
3. Disconnect client, send more messages
4. Reconnect client

### Expected behavior
Messages sent during step 3 above should display immediately upon reconnecting.

### Not working
```csharp
public async Task Connect(CancellationToken cancellationToken)
{
_cancellationToken = cancellationToken;

var optionsBuilder = new MqttClientOptionsBuilder()
.WithTcpServer(_traceOptions.Server, _traceOptions.Port)
.WithProtocolVersion(MQTTnet.Formatter.MqttProtocolVersion.V500)
.WithCleanSession(false)
.WithClientId(Dns.GetHostName());
if (_traceOptions.UseTls)
{
optionsBuilder = optionsBuilder.WithTls();
}

var options = optionsBuilder.Build();

await _client.ConnectAsync(options, _cancellationToken);
_logger.LogInformation("Connected to server {server}", _traceOptions.Server);
await Subscribe();
}
```

### Working
```csharp
public async Task Connect(CancellationToken cancellationToken)
{
_cancellationToken = cancellationToken;

var optionsBuilder = new MqttClientOptionsBuilder()
.WithTcpServer(_traceOptions.Server, _traceOptions.Port)
.WithProtocolVersion(MQTTnet.Formatter.MqttProtocolVersion.V311)
.WithCleanSession(false)
.WithClientId(Dns.GetHostName());
if (_traceOptions.UseTls)
{
optionsBuilder = optionsBuilder.WithTls();
}

var options = optionsBuilder.Build();

await _client.ConnectAsync(options, _cancellationToken);
_logger.LogInformation("Connected to server {server}", _traceOptions.Server);
await Subscribe();
}
```

Again, not sure if I'm missing something but it does almost seem like the client unsubscribes when it shuts down - but I don't want it to do this!

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.