Skip to content
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

Get all parameters at once to avoid conflicts in parallel testing #211

Merged
merged 4 commits into from
May 2, 2023

Conversation

Alejandro-SB
Copy link
Contributor

This PR should hopefully close #181.
A testing branch was created here to check the scenario.

As #181 explains, this problem arises when tests are being executed in parallel, randomly throwing ArgumentNullException in the AllStreamSubscription constructor.
After debugging this case, this was narrowed down to the SubscriptionBuilder.ResolveSubscription method. Although I still don't know exactly why, the execution goes as follows.
First, the GetConstructors<TOptions> extension method is called, returning the constructors that have TOptions as a parameter.

var constructors = typeof(T).GetConstructors<TOptions>();

This extension method returns the constructor and also the TOptions ParameterInfo in a tuple.
Then, in line 216, GetParameters is called again to get this constructor parameters and map them to their correct value.
var args = ctor.GetParameters().Select(CreateArg).ToArray();

Finally, in line 224, a check is run to see if the parameter being mapped to its correct value is the options parameter, to get them from the IMonitorOptions.

For some reason, when working in parallel, although they refer to the same parameter, they are completely different instances and don't match, omitting this check and returning null. To fix it, this PR returns only one array with the parameters of the constructor, avoiding the second call.
In the testing branch mentioned earlier, this behaviour can be replicated with ease. If line 220 is uncommented, test will start to fail, as now the GetParameters() method is returning different instances of the parameter.
Also, a System.Diagnostics.Debugger.Launch() is set in line 252 to debug this problem.

@CLAassistant
Copy link

CLAassistant commented Apr 28, 2023

CLA assistant check
All committers have signed the CLA.

@Alejandro-SB Alejandro-SB marked this pull request as ready for review April 28, 2023 11:05
@alexeyzimarev alexeyzimarev self-requested a review April 29, 2023 08:03
@alexeyzimarev alexeyzimarev merged commit 41a97f0 into Eventuous:dev May 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[EVE-33] Race condition in ESDB subscriptions with random NullReferenceException
3 participants