MQTTnet: MQTTnet.Exceptions.MqttProtocolViolationException: Received packet 'PubAck: [PacketIdentifier=21584] [ReasonCode=]' at an unexpected time.

Describe the bug

A clear and concise description of what the bug is.

Which project is your bug related to?

  • [ √] ManagedClient

To Reproduce

An error occurred while connecting to the mqtt service。 This problem exists with the latest version or 2.8.5 Using TCP This error occurs when the program is running on Windows 7 sp1, but it is normal in Windows 10.

Additional context / logging

MQTTnet.Exceptions.MqttProtocolViolationException: Received packet ‘PubAck: [PacketIdentifier=21584] [ReasonCode=]’ at an unexpected time.

Code example

var options = new ManagedMqttClientOptionsBuilder()
		.WithAutoReconnectDelay(TimeSpan.FromSeconds(5))
		.WithClientOptions(new MqttClientOptionsBuilder()
			.WithClientId(Guid.NewGuid().ToString())                            
			.WithTcpServer("127.0.0.1", 33382)
			.WithCredentials(brokerInfo.BrokerUser, brokerInfo.BrokerPassword)
			.WithCleanSession()
			.Build())
		.Build();
var mqttClient = new MqttFactory().CreateManagedMqttClient();
mqttClient.StartAsync(options);               
mqttClient.ConnectingFailedHandler = new FailedHandler();                
mqttClient.ConnectedHandler = new ConnectedHandler(lblWsState);

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 17 (3 by maintainers)

Most upvoted comments

I can’t explain how this happened, but we now have this issue as well with the latest version (Client and Server in use and both on 4.3.3.952). In our use case, there is a custom version of https://github.com/microsoft/reverse-proxy in between that was reset yesterday. Afterwards (No idea why), the exception occured out of nowhere.

I guess, if we restart all MQTT related services, it will work again… The problem is, that I can’t provide example code as the code is included in a really big code base. However, this still seems to be an issue after a random network abortion somewhere between the server and the client…

I will add some checks that a PUBREC from a previous connection will no longer throw this exception. I will check if a PUBREL can be sent indicating that the client doesn’t know the message anymore.

@Doyle-net Does this mean you fixed this issue and if yes how?