mParticle / mparticle-dotnet-sdk

2 stars 3 forks source link

Error is thrown during `MParticle.UploadAsync()` call. #12

Open ddemirci-ichoosr opened 2 years ago

ddemirci-ichoosr commented 2 years ago

Hello,

I want to consult you on an issue related to the SDK. In our API, we use the latest version of your SDK and have a code block below

_mParticle.LogEvent( new CustomEvent(eventDescription, eventType) {
        CustomAttributes = customAttributes
});

await _mParticle.UploadAsync();

After calling the UploadAsync() method of yours, I receive an error. That is Destination array was not long enough. Check the destination index, length, and the array's lower bounds. (Parameter 'destinationArray'). The related method is System.Array.Copy. The screenshot below is from Azure AppInsights

Azure

Starting from that point, I don't want to intervene in your codebase however I made some research to understand the reason for the error that I faced, and maybe the things I discovered will help you. In my opinion, the world becomes a better place if developers help other developers 😄

I cloned your SDK to my local environment and trace the codebase to be able to determine the exact place where the error is thrown.

In UploadQueue.Upload(object _, System.Timers.ElapsedEventArgs __) method, you are creating a list called baseEvents from another list called _events. My IDE, Rider, gives me a warning which is The field is sometimes used inside synchronized block and sometimes used without synchronization. A detailed description of the warning can be found in the official document of Rider.

The problem might be not using a thread-safe approach while creating the baseEvents collection.

Furthermore, I have found similar issues posted to Stackoverflow, and here are the links 1) https://stackoverflow.com/a/14118859 2) https://stackoverflow.com/a/28715820 3) https://stackoverflow.com/a/61627737

I am open to your thoughts and ideas. Hope the above helps you.