Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Avoid SafeHandle finalization from failed registry operations#71854

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged

Conversation

stephentoub
Copy link
Member

Fixes#71773

@ghost
Copy link

Tagging subscribers to this area: @dotnet/area-microsoft-win32
See info inarea-owners.md if you want to be subscribed.

Issue Details

Fixes#71773

Author:stephentoub
Assignees:stephentoub
Labels:

area-Microsoft.Win32

Milestone:-

Copy link
Member

@danmoseleydanmoseley left a comment

Choose a reason for hiding this comment

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

Just curious, do we make any attempt in tests of some sort to look for unintended finalizations? I guess without some kind of diagnostics into the GC there is no reliable way and we just rely on code inspection, and the unlikely situation of it being exposed by what stress tests we do run.

@danmoseleydanmoseley merged commit1605800 intodotnet:mainJul 11, 2022
@danmoseley
Copy link
Member

Thinking, perhaps it would look something like: an environment variable to disable the finalizer thread (does that exist?); then manually running a set of unit tests (presumably we have unit tests for invalid reg keys e.g.), forcing GC, and inspecting a dump to see objects pending finalization, perhaps focusing on certain types. Or simply events/tracing of finalizer activity .

@stephentoubstephentoub deleted the registrysafehandledispose branchJuly 11, 2022 11:56
@stephentoub
Copy link
MemberAuthor

stephentoub commentedJul 11, 2022
edited
Loading

Just curious, do we make any attempt in tests of some sort to look for unintended finalizations?

We've done things in the past like this:

#ifDEBUG
privatestaticreadonlybools_captureTrace=
Environment.GetEnvironmentVariable("DEBUG_SAFEX509HANDLE_FINALIZATION")!=null;
privatereadonlyStackTrace?_stacktrace=
s_captureTrace?newStackTrace(fNeedFileInfo:true):null;
~SafeX509Handle()
{
if(s_captureTrace)
{
Console.WriteLine($"0x{handle.ToInt64():x}{_stacktrace?.ToString()??"no stacktrace..."}");
}
}
#endif

I'll play around with what that would look like in the base type. That of course would only handle safe handles, only with a debug/checked runtime, and only if enabled.

@danmoseley
Copy link
Member

Curious how many hits we'd get if we ran our unit tests now with that pasted into SafeRegistryHandle, e.g.. I'm guessing leaky tests would hide such bugs. Would it be worth creating an issue in case a community member is interested in such an experiment? If it was not too painful they could then try with SafeFileHandle E.g.

@stephentoub
Copy link
MemberAuthor

I'm already working on it. It'sa lot.

@ghostghost locked asresolvedand limited conversation to collaboratorsAug 11, 2022
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.
Reviewers

@danmoseleydanmoseleydanmoseley approved these changes

Assignees

@stephentoubstephentoub

Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

Passing a path to a key that doesn't exist to OpenSubKey() causes a SafeRegistryHandle to be finalized
2 participants
@stephentoub@danmoseley

[8]ページ先頭

©2009-2025 Movatter.jp