Azure / Azure/azure-iot-sdk-csharp

Command Registration throws exception if a too big message was send before

Open
#3,484 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
C#
Stars
477
Forks
492
Avg merge
9h 55m
Merged PRs (30d)
2

Description

# Context
**OS:** Windows 11 Desktop x64
**Application's .NET Target Framework :** .NET 8.0 ASP.NET Core application
**Device:** Laptop
**SDK version used:** 1.42.3

## Description of the issue

We have a problem with "RegisterCommandHandlerAsync" if we send a message with a too large message body before. The process order is this:

1. Connect to IoT Hub
2. Send a large message -> Exception throws (this is ok)
3. Register command handler -> Exception throws (this should not throw)

## Console log of the issue
```
System.InvalidOperationException: Message size (559135 bytes) is too big to process. Maximum allowed payload size is 262143
at Microsoft.Azure.Devices.Client.Transport.Mqtt.MqttIotHubAdapter.ComposePublishPacketAsync(IChannelHandlerContext context, Message message, QualityOfService qos, String topicName)
at Microsoft.Azure.Devices.Client.Transport.Mqtt.MqttIotHubAdapter.SendMessageAsync(IChannelHandlerContext context, Message message)
at Microsoft.Azure.Devices.Client.Transport.Mqtt.MqttIotHubAdapter.WriteAsync(IChannelHandlerContext context, Object data)
at Microsoft.Azure.Devices.Client.Transport.Mqtt.MqttIotHubAdapter.SubscribeAsync(IChannelHandlerContext context, SubscribePacket packetPassed)
at Microsoft.Azure.Devices.Client.Transport.Mqtt.MqttIotHubAdapter.WriteAsync(IChannelHandlerContext context, Object data)
at Microsoft.Azure.Devices.Client.Transport.Mqtt.MqttTransportHandler.EnableMethodsAsync(CancellationToken cancellationToken)
at Microsoft.Azure.Devices.Client.Transport.ErrorDelegatingHandler.<>c__DisplayClass27_0.<b__0>d.MoveNext()
--- End of stack trace from previous location ---
at Microsoft.Azure.Devices.Client.Transport.ErrorDelegatingHandler.ExecuteWithErrorHandlingAsync[T](Func`1 asyncOperation)
at Microsoft.Azure.Devices.Client.Transport.RetryDelegatingHandler.<>c__DisplayClass30_0.<b__0>d.MoveNext()
--- End of stack trace from previous location ---
at Microsoft.Azure.Devices.Client.TransientFaultHandling.RetryPolicy.<>c__DisplayClass34_0.<g__TaskWrapper|0>d.MoveNext()
--- End of stack trace from previous location ---
at Microsoft.Azure.Devices.Client.TransientFaultHandling.RetryPolicy.RunWithRetryAsync[T](Func`1 taskFunc, ShouldRetry shouldRetry, Func`2 isTransient, Action`3 onRetrying, Boolean fastFirstRetry, CancellationToken cancellationToken)
at Microsoft.Azure.Devices.Client.TransientFaultHandling.RetryPolicy.RunWithRetryAsync(Func`1 taskFunc, ShouldRetry shouldRetry, Func`2 isTransient, Action`3 onRetrying, Boolean fastFirstRetry, CancellationToken cancellationToken)
at Microsoft.Azure.Devices.Client.Transport.RetryDelegatingHandler.EnableMethodsAsync(CancellationToken cancellationToken)
at Microsoft.Azure.Devices.Client.InternalClient.HandleMethodEnableAsync(CancellationToken cancellationToken)
at Microsoft.Azure.Devices.Client.InternalClient.SetMethodHandlerAsync(String methodName, MethodCallback methodHandler, Object userContext, CancellationToken cancellationToken)
at Deos.P126.Cloud.Gate.Infrastructure.Iot.Azure.DigitalTwin.RegisterCommandHandlerAsync[T,TX](String commandName, ICommand`2 command, CancellationToken cancellationToken)
```

Contributor guide

Open the contributing guide

Research direction

Start with the stack trace in MqttIotHubAdapter.EnableMethodsAsync and follow it through InternalClient.SetMethodHandlerAsync. Reproduce the sequence of sending an oversized message followed by command registration, then verify that registration no longer propagates the earlier message-size exception. No test file or reproduction project is provided, so locating the relevant test coverage will require repository research.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure, csharp
Domain
embedded-iot
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.