-
Notifications
You must be signed in to change notification settings - Fork 163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: do not recreate Random each time #945
Conversation
On .NET Framework it is incorrect to recreate Random instances each time, these should instead be one per instance. On .NET Core and later this is not a limitation, but the libraries share a codebase. Fixes box#944
Hi @watfordsuzy |
For .NET Core and beyond you don't strictly need to re-use it (but should) as the underlying implementation already gives you a Thread Safe implementation: On .NET Framework a thread local Random could be used instead, but there are some interesting caveats if you go and read the comments regarding |
There is also an explicit thread safe implementation for If you want to work on this further, I think a thread-safe solution is the way to go. The overhead of potential locks shouldn't be a big deal, since this feature is already used to delay subsequent api calls, so that would just mean a slight bigger delay. While arguably making it not thread-safe isn't such a big deal either, it might result in slightly different behavior in multi-threaded environment compared to the single-threaded one. If necessary it's also possible to provide two implementation for both SDKs with pragmas. See example
|
I've gone ahead and made the suggested change, adapting their internal |
I don't believe the Integration Test failures are related @mwwoda |
Don't worry about the integration tests. Unfortunately, we cannot currently run them on forks. |
The code looks pretty good. I see that you have introduced a modern implementation for .NET6+ too which is great. Unfortunately, I just checked that when you use a conditional compilation flag such as |
@mwwoda no worries! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Will be included in the next release of the SDK.
On .NET Framework it is incorrect to recreate Random instances each time, these should instead be one per instance. On .NET Core and later this is not a limitation, but the libraries share a codebase.
Fixes #944