Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BugFix(MQTT): send an event in ReceiveMessageHandler before completin… #3116

Merged
merged 2 commits into from
Feb 16, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions e2e/test/iothub/messaging/MessageReceiveE2ETests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -938,6 +938,9 @@ await deviceClient.SetReceiveMessageHandlerAsync(
async (message, context) =>
{
VerboseTestLogger.WriteLine($"Received message over the first message handler: MessageId={message.MessageId}");
var messageD2C = new Client.Message(Encoding.UTF8.GetBytes("DeviceToCloud"));
// sending an event within message handler to make sure its flow is not affected by the event.
await deviceClient.SendEventAsync(messageD2C);
await deviceClient.CompleteAsync(message).ConfigureAwait(false);
firstHandlerSemaphore.Release();
},
Expand Down
4 changes: 1 addition & 3 deletions iothub/device/src/Transport/Mqtt/MqttTransportHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -578,9 +578,7 @@ private async Task HandleIncomingMessagesAsync()
// We are intentionally not awaiting _deviceMessageReceivedListener callback.
// This is a user-supplied callback that isn't required to be awaited by us. We can simply invoke it and continue.
_ = _deviceMessageReceivedListener?.Invoke(message);
// Messages with QoS = 1 need to be Acknowledged otherwise it results in mismatched Ack to IoT Hub
// causing next message being replayed and all subsequent messages being queued.
await CompleteIncomingMessageAsync(message).ConfigureAwait(false);
tmahmood-microsoft marked this conversation as resolved.
Show resolved Hide resolved
await TaskHelpers.CompletedTask.ConfigureAwait(false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why await this instead of removing the async keyword from the method?


if (Logging.IsEnabled)
Logging.Exit(this, "Process C2D message via callback", nameof(HandleIncomingMessagesAsync));
Expand Down