GithubHelp home page GithubHelp logo

Comments (7)

japf avatar japf commented on May 31, 2024

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.

japf avatar japf commented on May 31, 2024

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.

jasmineymlo avatar jasmineymlo commented on May 31, 2024

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.

japf avatar japf commented on May 31, 2024

from azure-iot-sdk-csharp.

jasmineymlo avatar jasmineymlo commented on May 31, 2024

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.

japf avatar japf commented on May 31, 2024

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.

jasmineymlo avatar jasmineymlo commented on May 31, 2024

Thanks for letting us know about this bug. Here is the commit:
d533f98

from azure-iot-sdk-csharp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.