MqttRpcClient.ExecuteRpcAsync no longer works if MqttClient already has a message receive handler
See original GitHub issueDescribe the bug
After updating from 3.0.12 to 3.0.14, MqttRpcClient.ExecuteRpcAsync no longer works properly if underlying MqttClient has its own MqttApplicationMessageReceivedHandler.
RpcAwareApplicationMessageReceivedHandler looks like it was changed to return immediately after OriginalHandler instead of also calling MqttRpcClient’s handler.
Which project is your bug related to?
- MQTTnet.Extensions.Rpc
To Reproduce
Steps to reproduce the behavior:
- Using version MQTTnet ‘3.0.14’
- Create a MqttClient or ManagedMqttClient
- Add ApplicationMessageReceivedHandler handler to the client
- Create a MqttRpcClient using this same client
- Run ‘ExecuteRpcAsync’
- MqttClient message received handler is called
- MqttRpcClient message handler is skipped
- ExecuteRpcAsync fails
Expected behavior
- MqttRpcClient.ExecuteRpcAsync should work if using a MqttClient or ManagedMqttClient that already has its own message receive handler.
- Verified that RPC_Tests only work because the MqttRpcClient is using a response MqttClient without its own ApplicationMessageReceivedHandler so they do not exercise the OriginalHandler condition.
Screenshots
Bug appears to have been introduced with this change from awaits to returns…

Proposed Fix: ExecuteRpcAsynce works properly again by simply removing the immediate return after calling OriginalHandler
.
public Task HandleApplicationMessageReceivedAsync(MqttApplicationMessageReceivedEventArgs eventArgs)
{
if (OriginalHandler != null)
{
OriginalHandler.HandleApplicationMessageReceivedAsync(eventArgs);
}
return _handleReceivedApplicationMessageAsync(eventArgs);
}
Issue Analytics
- State:
- Created 3 years ago
- Comments:8
Top Results From Across the Web
MqttRpcClient.ExecuteRpcAsync no longer works if ...
MqttRpcClient.ExecuteRpcAsync should work if using a MqttClient or ManagedMqttClient that already has its own message receive handler.
Read more >MQTT client not receiving messages sent by another client
The issue is that when you first connect the library does not know about your handlers until you tell it (generally with a...
Read more >MQTT Client, MQTT Broker, and MQTT Server Connection ...
Since the broker has a public address and maintains the connection open to enable bidirectional sending and receiving of messages (after the ...
Read more >View MQTT messages with the AWS IoT MQTT client
This section describes how to use the AWS IoT MQTT test client in the AWS IoT console to watch the MQTT messages sent...
Read more >mqttclient.subscribe(topics, qos, callback) - Dev Center
If this succeeds in turn, the code registers the handler that will log any incoming messages that have been posted to the chosen...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

@BrianG500 In my opinion the issue is that both handlers must be called in order to work correctly. Currently only one is called and the method returns. I fixed this in master. Now both handlers are invoked properly. Please let me know if this fixes your issue.
I will close this because it is fixed in 3.0.15-rc2.