Comments (7)
Update:
After debugging our code with the code of the SDK, I was able to find out the root cause. Before sending the message via SendEventAsync() we log it, and we call the GetBytes() method.
It turns out that calling GetBytes() once prevent the message from being sent properly. What is weird is that if we call GetByes() twice we can an exception but calling GetBytes() and SendEventAsync() fails silently.
I will try to submit a PR if I find a way to improve this behavior.
from azure-iot-sdk-csharp.
Looks like the source of this problem is in the SendMessageWithRetryAsync method:
async Task SendMessageWithRetryAsync(SendMessageState sendState, Message message, Func<Task> action)
{
if (sendState.Iteration == 0)
{
sendState.InitialStreamPosition = message.BodyStream.CanSeek ? message.BodyStream.Position : UndeterminedPosition;
message.TryResetBody(sendState.InitialStreamPosition);
await TryExecuteActionAsync(sendState, action);
return;
}
EnsureStreamIsInOriginalState(sendState, message);
await TryExecuteActionAsync(sendState, action);
}
Since we called the GetBytes() method before reaching this one, we're going to set the InitialStreamPosition to the end of the stream.
Please let me know if that is clear enough. I also would welcome guidance about how to fix that in the source so that I can propose a PR.
from azure-iot-sdk-csharp.
Hi Japf,
You mentioned that the code works fine with v1.0.11, were you calling GetBytes() to log the message before sending also?
Regards,
Jasmine
from azure-iot-sdk-csharp.
from azure-iot-sdk-csharp.
Hi Japf,
I can repro the issue is v1.0.12 as well and it is fine on v1.0.11. The issue is surfaced due to the fix for taking care of non-seekable stream. Originally, the stream position is hard reset to the beginning before send. Removing the hard reset surfaced the bug in GetBytes()
The proposed fix would be to reset the position in within GetBytes() after reading the stream so that the position would not be altered after the call. I should have the fix ready in next release.
Btw, why are you using GetBytes for logging send messages? You should be able to log using the byte[] which is used for creating the Message object. Thanks.
Regards,
Jasmine
from azure-iot-sdk-csharp.
I don't have a good reason for using GetBytes() to log the message, the code was just written this way :-)
from azure-iot-sdk-csharp.
Thanks for letting us know about this bug. Here is the commit:
d533f98
from azure-iot-sdk-csharp.
Related Issues (20)
- AOT-compatible Microsoft.Azure.Devices.Client HOT 1
- SDK version :2.0.0-preview007 CreateAsync() Json Error
- [Bug Report] WebSockets not working on Web Assembly HOT 1
- Latest device client does not connect over MQTT HOT 9
- Errors while running e2e tests with .NET 8.0 HOT 1
- How to use tpm private key for TLS with IoT Hub SDK (Not TPM Attestation) - for DeviceAuthenticationWithX509Certificate HOT 4
- [Bug Report] AMQP DeviceClient is slow to respond to device being disabled
- Desired Properties callback not triggering after a reconnect HOT 5
- [feature request] Move to System.Text.Json to support AOT HOT 2
- [Bug Report] DeviceClient.SendEventAsync takes over one minute after update from 1.42.0 to 1.42.2 HOT 7
- [BUG] error CS0426: The type name 'Create' does not exist in the type 'ServiceClient' HOT 1
- Building digital twin of the robotic arm [Technical Question] HOT 2
- How do I send data stored in array (floating type) from my robot to IoT hub? [Technical Question]
- [Bug Report] Fails to establish TPM connection HOT 1
- [Technical Question] Security: Check root certificate on device-to-cloud connection HOT 10
- Unhandled exception. Microsoft.Azure.Devices.Client.Exceptions.IotHubException: Request 817bda7c-6fc4-40e0-8946-93eb851fcb12 returned status 403 [Bug Report] HOT 7
- [Bug Report] Send message in batch to multiple outputs using ModuleClient throws HOT 1
- Is it possible to send bulk messages in telemetry from device to IoT hub? [Technical Question]
- [Technical Question] HttpClientHelper error code 400030 HOT 3
- [Bug Report] When try to fetch reported properties after updating the reported property it will return previous version of reported property not the latest one. HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from azure-iot-sdk-csharp.