Skip to content

Fix keep alive detection during publishing - #2259

Open
suhashollakc wants to merge 1 commit into
dotnet:masterfrom
suhashollakc:suhas/fix-keepalive-during-publish
Open

suhashollakc wants to merge 1 commit into
dotnet:masterfrom
suhashollakc:suhas/fix-keepalive-during-publish

Conversation

@suhashollakc

Copy link
Copy Markdown
Contributor

Fixes #2244

Summary

This fixes keep-alive detection when a client continuously publishes QoS 0 messages over a half-open connection.

The keep-alive loop previously considered only the last packet sent. Periodic publishes kept refreshing that timestamp even when the broker returned no traffic, so the client never sent a PINGREQ and DisconnectedAsync could remain silent indefinitely.

Changes

  • Track the timestamp of the last packet received from the broker.
  • Send a keep-alive ping when either outbound MQTT traffic is overdue or no inbound traffic has been observed for the keep-alive interval.
  • Add a deterministic regression test using an adapter that accepts publishes but lets PINGREQ time out.

Validation

  • dotnet test --project Source\MQTTnet.Tests\MQTTnet.Tests.csproj --framework net10.0 --no-restore --filter "KeepAlive_Timeout_Raises_Disconnected_While_Publishing|KeepAlive_Ping_Send_Timeout_Raises_Disconnected|Publish_QoS_0_Over_Period_Exceeding_KeepAlive"
  • dotnet test --project Source\MQTTnet.Tests\MQTTnet.Tests.csproj --framework net10.0 --no-restore --filter FullyQualifiedName~MQTTnet.Tests.Clients.MqttClient.MqttClient_Tests
  • dotnet build MQTTnet.slnx --no-restore

The solution build succeeds with the existing ASP.NET benchmark deprecation warnings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DisconnectedAsync is not raised if (failed) Publish attempts were made

1 participant