Skip to content

fix race condition for test MulticlassTreeFeaturizedLRTest#4950

Merged
frank-dong-ms-zz merged 3 commits intodotnet:masterfrom
frank-dong-ms-zz:fix-MulticlassTreeFeaturizedLRTest
Mar 18, 2020
Merged

fix race condition for test MulticlassTreeFeaturizedLRTest#4950
frank-dong-ms-zz merged 3 commits intodotnet:masterfrom
frank-dong-ms-zz:fix-MulticlassTreeFeaturizedLRTest

Conversation

@frank-dong-ms-zz
Copy link
Contributor

method in TreeEnsembleFeaturizerTransform will be called from multi-threading, make variable "temp" as local variable to avoid race condition.

@frank-dong-ms-zz frank-dong-ms-zz requested a review from a team as a code owner March 18, 2020 06:18
mapper =
(in TInput src, ref Single dst) =>
{
ulong temp = 0;
Copy link
Contributor

@harishsk harishsk Mar 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice find! :-) Can you please add some comments about this change? Otherwise some future developer might want to "optimize" this and move it back.

Also, this pattern deserves more investigation. Do we have other mappers that are using variables set outside the mapper function definition? #Resolved

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, sure, I will add comments on this.


In reply to: 394130751 [](ancestors = 394130751)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sharwell do you have any tool recommendation to detect similar race condition issue either static code analyze or run time detection?


In reply to: 394131983 [](ancestors = 394131983,394130751)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No similar issue found from other mappers but mapper are not only function used in multi-threading condition and it is impossible to view for all similar issue.


In reply to: 394130751 [](ancestors = 394130751)

Copy link
Contributor

@sharwell sharwell Mar 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not aware of such a tool. It would be easier to write a more targeted tool that identified variables captured by a lambda so they could be reviewed for cases like this. #Resolved

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, thanks


In reply to: 394334398 [](ancestors = 394334398)

(in TInput src, ref Single dst) =>
{
// Attention: this method will be used in multipe threading,
// don't put temp variable outside of this method to avoid race condition
Copy link
Contributor

@harishsk harishsk Mar 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: The comment is slightly confusing. Can you please rephrase it? Say, something like:

This method is called from multiple threads. Do not move the temp variable outside this method. If you do, the variable is shared between the threads and results in a race condition. #Resolved

Copy link
Contributor

@harishsk harishsk Mar 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isnt there a test that can be enabled back because of this fix? #Resolved

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the test (MulticlassTreeFeaturizedLRTest) is not disabled but I see several fail on machine learning full test set.
As test machine only has 2 cores so the failure rate is not that high but if we run the test locally the failure rate is more than 10 percent.


In reply to: 394607002 [](ancestors = 394607002)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, thanks


In reply to: 394606675 [](ancestors = 394606675)

@frank-dong-ms-zz frank-dong-ms-zz merged commit 26ffb3f into dotnet:master Mar 18, 2020
@frank-dong-ms-zz frank-dong-ms-zz deleted the fix-MulticlassTreeFeaturizedLRTest branch April 7, 2020 04:29
@ghost ghost locked as resolved and limited conversation to collaborators Mar 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants