dotnet/runtime

PerformanceCounterLib calls RegistryKey.OpenRemoteBaseKey with incorrect machine name

Open

#33,506 opened on 2020年3月12日

GitHub で見る
 (9 comments) (0 reactions) (0 assignees)C# (5,445 forks)batch import
area-System.Diagnostics.PerformanceCounterhelp wanted

Repository metrics

Stars
 (17,886 stars)
PR merge metrics
 (平均マージ 12d 11h) (30d で 661 merged PRs)

説明

Hey all - I think there is a bug with opening performance counters on remote machines. I have noticed that we have different behaviour to PDH, and I'm fairly certain theirs is correct.

Whilst the documentation for OpenRemoteBaseKey doesn't say much about the format of machineName, if we look at the docs for RegConnectRegistryW we see

The name of the remote computer. The string has the following form:

\computername

I do suspect that even this is a typo and it should be \\computername but the second \ has been eaten as an escape.

If we look at PerformanceCounterLib we do the right thing in one place https://github.com/dotnet/runtime/blob/master/src/libraries/System.Diagnostics.PerformanceCounter/src/System/Diagnostics/PerformanceCounterLib.cs#L678 , but the other two calls https://github.com/dotnet/runtime/blob/master/src/libraries/System.Diagnostics.PerformanceCounter/src/System/Diagnostics/PerformanceCounterLib.cs#L1044 and https://github.com/dotnet/runtime/blob/master/src/libraries/System.Diagnostics.PerformanceCounter/src/System/Diagnostics/PerformanceCounterLib.cs#L1286 seem to be doing the wrong thing. This bug also appears to exist in .NET Framework - and actually that's where I first noticed this issue.

This appears to make it impossible, at least on my machine, to use the .NET perf counter library against a remote machine. Unfortunately we can't pass in the correct machine name as we 'validate' the machine name and ensure it does not contain any \ characters! So far as I can tell this should be an easy fix, but I am surprised that it has gone undetected for so long.

コントリビューターガイド