question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

MqttRpcClient.ExecuteRpcAsync no longer works if MqttClient already has a message receive handler

See original GitHub issue

Describe 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:

  1. Using version MQTTnet ‘3.0.14’
  2. Create a MqttClient or ManagedMqttClient
  3. Add ApplicationMessageReceivedHandler handler to the client
  4. Create a MqttRpcClient using this same client
  5. Run ‘ExecuteRpcAsync’
  6. MqttClient message received handler is called
  7. MqttRpcClient message handler is skipped
  8. 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… image

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:closed
  • Created 3 years ago
  • Comments:8

github_iconTop GitHub Comments

1reaction
chkr1011commented, Feb 18, 2021

@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.

0reactions
chkr1011commented, Feb 21, 2021

I will close this because it is fixed in 3.0.15-rc2.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found