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

PerformanceCounter tests failing in CI #44208

Closed
stephentoub opened this issue Nov 3, 2020 · 17 comments
Closed

PerformanceCounter tests failing in CI #44208

stephentoub opened this issue Nov 3, 2020 · 17 comments
Labels
area-VM-coreclr blocking-clean-ci Blocking PR or rolling runs of 'runtime' or 'runtime-extra-platforms' bug tenet-reliability Reliability/stability related issue (stress, load problems, etc.)

Comments

@stephentoub
Copy link
Member

Inconsistently but frequently, PRs in CI have been failing tests from the System.Diagnostics.Tests.PerformanceCounterTests suite. When one test fails, a ton fail. They all look along the lines of this:

Error message
System.InvalidCastException : Unable to cast object of type 'System.String' to type 'System.String[]'.

Stack trace
   at System.Diagnostics.SharedPerformanceCounter.GetCategoryData() in /_/src/libraries/System.Diagnostics.PerformanceCounter/src/System/Diagnostics/SharedPerformanceCounter.cs:line 700
   at System.Diagnostics.SharedPerformanceCounter..ctor(String catName, String counterName, String instanceName, PerformanceCounterInstanceLifetime lifetime) in /_/src/libraries/System.Diagnostics.PerformanceCounter/src/System/Diagnostics/SharedPerformanceCounter.cs:line 96
   at System.Diagnostics.SharedPerformanceCounter..ctor(String catName, String counterName, String instanceName) in /_/src/libraries/System.Diagnostics.PerformanceCounter/src/System/Diagnostics/SharedPerformanceCounter.cs:line 88
   at System.Diagnostics.SharedPerformanceCounter.RemoveAllInstances(String categoryName) in /_/src/libraries/System.Diagnostics.PerformanceCounter/src/System/Diagnostics/SharedPerformanceCounter.cs:line 1389
   at System.Diagnostics.PerformanceCounterCategory.Delete(String categoryName) in /_/src/libraries/System.Diagnostics.PerformanceCounter/src/System/Diagnostics/PerformanceCounterCategory.cs:line 395
   at System.Diagnostics.Tests.Helpers.DeleteCategory(String name) in /_/src/libraries/System.Diagnostics.PerformanceCounter/tests/Helpers.cs:line 46
   at System.Diagnostics.Tests.Helpers.CreateCategory(String name, PerformanceCounterCategoryType categoryType) in /_/src/libraries/System.Diagnostics.PerformanceCounter/tests/Helpers.cs:line 22
   at System.Diagnostics.Tests.PerformanceCounterTests.CreateCounterWithCategory(String name, Boolean readOnly, PerformanceCounterCategoryType categoryType) in /_/src/libraries/System.Diagnostics.PerformanceCounter/tests/PerformanceCounterTests.cs:line 293
   at System.Diagnostics.Tests.PerformanceCounterTests.PerformanceCounter_Decrement() in /_/src/libraries/System.Diagnostics.PerformanceCounter/tests/PerformanceCounterTests.cs:line 186

e.g. https://dev.azure.com/dnceng/public/_build/results?buildId=874236&view=ms.vss-test-web.build-test-results-tab&runId=27965576&resultId=121120&paneView=debug

@stephentoub stephentoub added area-System.Diagnostics blocking-clean-ci Blocking PR or rolling runs of 'runtime' or 'runtime-extra-platforms' labels Nov 3, 2020
@ghost
Copy link

ghost commented Nov 3, 2020

Tagging subscribers to this area: @tommcdon, @krwq
See info in area-owners.md if you want to be subscribed.

@danmoseley
Copy link
Member

danmoseley commented Nov 3, 2020

Apparently "Counter Names" may be String or Multistring? the code expects the latter.

My guess is that here

string[] counterNames = (string[])counterNamesObject;
for (int i = 0; i < counterNames.Length; i++)
counterNames[i] = counterNames[i].ToLowerInvariant();
data.CounterNames = new ArrayList(counterNames);

It simply needs to use GetValueKind to figure whether to cast to string or string[] and then proceed.

@danmoseley
Copy link
Member

@Anipik owns S.D.PerformanceCounter.

@stephentoub
Copy link
Member Author

@steveisok hit the new assert:

Process terminated. Assertion failed.
Expected string[], got 'System.String[]' with kind 'String'for category 'averagecounter64samplecategory'
   at System.Diagnostics.Tests.CounterCreationDataCollectionTests.PerformanceCounterCategory_CreateCategory() in /_/src/libraries/System.Diagnostics.PerformanceCounter/tests/CounterCreationDataCollectionTests.cs:line 124

https://helixre8s23ayyeko0k025g8.blob.core.windows.net/dotnet-runtime-refs-pull-44046-merge-146881d67d7c4c7ba9/System.Diagnostics.PerformanceCounter.Tests/console.210349c5.log?sv=2019-07-07&se=2020-11-25T20%3A35%3A23Z&sr=c&sp=rl&sig=gYGgvImTcGJ99mVVeSk%2Bg%2BucMp92%2F6xeEerbQTpkqv8%3D

#44332

@stephentoub
Copy link
Member Author

stephentoub commented Nov 5, 2020

This assert output is really weird. The assert I added is:

Debug.Assert(counterNamesObject is string[], $"Expected string[], got '{counterNamesObject}' with kind '{categoryKey.GetValueKind("Counter Names")}'for category '{_categoryName}'");

So the above shows it failing an is string[] check, but then its ToString is reporting that it's a System.String[].

@jkotas, does this ring any bells? Could this be related to casting changes?

Unless... maybe it actually is a String with the value "System.String[]"?! I'll update the assert.

@danmoseley
Copy link
Member

Well, that's our test

public static void PerformanceCounterCategory_CreateCategory()

But it's just going through our API's.

@danmoseley
Copy link
Member

Oops, of course it's written by our test 😄

@steveisok
Copy link
Member

I tried finding this kind of issue first. I searched for "PerformanceCounters" and found 3 unrelated issues :-)

@jkotas
Copy link
Member

jkotas commented Nov 5, 2020

@jkotas, does this ring any bells? Could this be related to casting changes?

Yes, I think this looks like race condition in the lock-free hashtable used by casting.

@VSadov Could you please take a look?

@jkotas jkotas added area-VM-coreclr bug tenet-reliability Reliability/stability related issue (stress, load problems, etc.) and removed area-System.Diagnostics labels Nov 5, 2020
@VSadov
Copy link
Member

VSadov commented Nov 5, 2020

Will take a look. Thanks!

@VSadov
Copy link
Member

VSadov commented Nov 5, 2020

@stephentoub - did this start recently or was like this for months?

@stephentoub
Copy link
Member Author

To my knowledge, recently.

@VSadov
Copy link
Member

VSadov commented Nov 5, 2020

Exception message should generally be correct about types.
string[] --> string[] would be an identity conversion. It should not use cache, unless something bad happened with the type system (i.e. two distinct string types)

I think it is more likely that we are getting a string with System.String[] content somehow.

The new assert in #44333 is a good idea - should help to verify this.

@VSadov
Copy link
Member

VSadov commented Nov 6, 2020

Any new failures? Is there a way to check?

@stephentoub
Copy link
Member Author

stephentoub commented Nov 7, 2020

I haven't seen any more but I'm also not at my computer to run a query right now. (I'm also wondering if this could possibly have been another effect of #44250? I haven't lined things up exactly, but the timing seems to correlate.)

@stephentoub
Copy link
Member Author

According to Kusto, this failed ~300 times on 11/2, ~100 times on 11/3, and then hasn't failed since.

@jkotas
Copy link
Member

jkotas commented Nov 13, 2020

Likely another effect of #44250

@jkotas jkotas closed this as completed Nov 13, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-VM-coreclr blocking-clean-ci Blocking PR or rolling runs of 'runtime' or 'runtime-extra-platforms' bug tenet-reliability Reliability/stability related issue (stress, load problems, etc.)
Projects
None yet
Development

No branches or pull requests

5 participants