Closed
Description
I hit a bug with Optimizely C# SDK when toying in "short lived" console app. The issue is mainly that the SDK does not employ C# async/await best practice "Async All the Way". Reference can be here.
The problematic code is here and the usages are here. And the two scenarios that I came up with are as below:
//Scenario 1
var client = new Optimizely(dataFile);
client.Activate("experimentId", "userId", attrs);
//Activate() will call SendImpressionEvent() which calls EventDispatcher.DispatchEvent(impressionEvent); But Activate() does not have an async method signature, hence not possible to await on the response.
client.Track("Clicks", "userId");
//By th
5584
e time Track() is called, if above DispatchEvent is still in-flight (not complete), I'm assuming Track() will fail due to "userId" has not been activated for "experimentId".
//Scenario 2
var client = new Optimizely(dataFile);
client.Activate("experimentId", "userId", attrs);
client.Track("Clicks", "userId");
//At this point in time, my console app exits, because Track() does not have an async method signature, hence I'm not able to tell if the DispatchEvent inside Track() has completed successfully ot not.
I'll also submit a PR for fix soon.
Update:
Having had a bit more time to think about this issue, I believe it is best for DispatchEvent() to be sequential and not fire & forget. For fire & forget, it is best to be more explicit in terms of method signature.
Proposed change is here:
https://github.com/HistoricallyCorrect/csharp-sdk/commit/44ffbbfd2598bcd9a60d678b88d1e667d1865eab
Metadata
Metadata
Assignees
Labels
No labels