Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Using IMetaDataEmit::DeleteToken causes the runtime to hang #114306

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

Open
urisimchoni opened this issue Apr 6, 2025 · 6 comments
Open

Using IMetaDataEmit::DeleteToken causes the runtime to hang #114306

urisimchoni opened this issue Apr 6, 2025 · 6 comments
Labels
area-Diagnostics-coreclr needs-author-action An issue or pull request that requires more info or actions from the author. question Answer questions and provide assistance, not an issue with source code or documentation.
Milestone

Comments

@urisimchoni
Copy link
Contributor

I have a .Net profiler (using the native profiler interface). I'm able to instrument code and and use IMetaDataEmit interface to create tokens (e.g. TypeRefs and MemberRefs). However when I try to use DeleteToken() to delete an assembly-scoped custom attribute the program hangs. I tried this from various callbacks (module load finished, assembly load finished, JITStarted) - all resulting the same.

I find the custom attribute token by enumerating custom attribute, close the enumerator, and then try the DeleteToken(), and the runtime hangs.

This happens in all runtime versions I've checked. Probably I'm doing something wrong here, but before providing a full reproducer I'd like to know whether there are known limitations to DeleteToken() or maybe there are better approaches to deleting custom attributes at runtime.

Thanks,
Uri.

@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label Apr 6, 2025
@tommcdon tommcdon added the question Answer questions and provide assistance, not an issue with source code or documentation. label Apr 6, 2025
@tommcdon tommcdon added this to the 10.0.0 milestone Apr 6, 2025
@tommcdon tommcdon removed the untriaged New issue has not been triaged by the area owner label Apr 6, 2025
@tommcdon
Copy link
Member

tommcdon commented Apr 6, 2025

@noahfalk @mdh1418

@noahfalk
Copy link
Member

noahfalk commented Apr 6, 2025

Hi @urisimchoni!

Unfortunately, I suspect delete operations on metadata aren't supported under the profiler (or at least they've probably never been tested). Traditionally all the profiler metadata support was in service of editing existing IL code or writing new IL code so that profilers could do instrumentation. For those tasks tokens sometimes became unreferenced but it wasn't necessary to delete them.

I think your options would be:

  • searching for some alternative way to do your scenario that doesn't require deleting custom attributes
  • if you are motivated enough you could try to add support yourself via a PR (if you do this please let us know you are thinking of so we can make sure the approach seems good before spending lots of time on a PR)
  • we could convert this issue into a request for the runtime team to add the support. In that case we'd need more info from you about how this would get used and what value it would bring to .NET developers to help us prioritize it. I don't want to judge prematurely but I do want to warn in general there are many requests we are never able to get to.

Sorry I don't have any quick fix for you on this one. Let us know if you want to pursue one of those options or you have any other questions around this.

@noahfalk noahfalk added the needs-author-action An issue or pull request that requires more info or actions from the author. label Apr 6, 2025
@jkotas
Copy link
Member

jkotas commented Apr 7, 2025

the program hangs

What's the stacktrace of the hang?

@urisimchoni
Copy link
Contributor Author

the program hangs

What's the stacktrace of the hang?

Is there a way to get symbol info for dotnet binaries without building? The windbg stack is not very helpful

     # Child-SP          RetAddr               Call Site
00 00000019`12b7b1c8 00007ff9`1a74c7af     ntdll!NtWaitForSingleObject+0x14
01 00000019`12b7b1d0 00007ff8`f5a858b5     KERNELBASE!WaitForSingleObjectEx+0xaf
02 00000019`12b7b270 00007ff8`f5958203     coreclr!coreclr_set_error_writer+0x5a545
03 00000019`12b7b2a0 00007ff8`f5c4d840     coreclr+0x88203
04 00000019`12b7b2d0 00007ff8`f5c3cf00     coreclr!GetCLRRuntimeHost+0x16b8a0
05 00000019`12b7b310 00007ff8`e74a6015     coreclr!GetCLRRuntimeHost+0x15af60
06 00000019`12b7b3b0 00007ff8`e747710e     vfagent_net!DllGetClassObject+0x2eb65
07 00000019`12b7be30 00007ff8`f5b3310a     vfagent_net!DllCanUnloadNow+0x65fe
08 00000019`12b7be60 00007ff8`f5ad0ca7     coreclr!GetCLRRuntimeHost+0x5116a
09 00000019`12b7bea0 00007ff8`f5ab7150     coreclr!coreclr_set_error_writer+0xa5937
0a 00000019`12b7bed0 00007ff8`f5928172     coreclr!coreclr_set_error_writer+0x8bde0
0b 00000019`12b7bf50 00007ff8`f5928269     coreclr+0x58172
0c 00000019`12b7bf90 00007ff8`f5928aae     coreclr+0x58269
0d 00000019`12b7c080 00007ff8`f59398c4     coreclr+0x58aae
0e 00000019`12b7c100 00007ff8`f5939652     coreclr+0x698c4
0f 00000019`12b7c210 00007ff8`f595f22b     coreclr+0x69652
10 00000019`12b7c500 00007ff8`f5937f4e     coreclr+0x8f22b
11 00000019`12b7c610 00007ff8`f58e7f16     coreclr+0x67f4e
12 00000019`12b7c6b0 00007ff8`f58e7302     coreclr+0x17f16
13 00000019`12b7c7a0 00007ff8`f58e620a     coreclr+0x17302
14 00000019`12b7c8f0 00007ff9`007ad92f     coreclr+0x1620a
15 00000019`12b7cbf0 00007ff9`007aa322     clrjit+0xcd92f
16 00000019`12b7d400 00007ff9`007a9ff1     clrjit+0xca322
17 00000019`12b7d500 00007ff9`007c457e     clrjit+0xc9ff1
18 00000019`12b7d570 00007ff9`0070d3a0     clrjit+0xe457e
19 00000019`12b7d5a0 00007ff9`007a882f     clrjit+0x2d3a0
1a 00000019`12b7d850 00007ff9`007a7c1d     clrjit+0xc882f
1b 00000019`12b7d930 00007ff9`0073b015     clrjit+0xc7c1d
1c 00000019`12b7da20 00007ff9`007c7836     clrjit+0x5b015
1d 00000019`12b7dbc0 00007ff8`f5963f3f     clrjit+0xe7836
1e 00000019`12b7dc60 00007ff8`f596767b     coreclr+0x93f3f
1f 00000019`12b7e1b0 00007ff8`f59674a2     coreclr+0x9767b
20 00000019`12b7e2c0 00007ff8`f59671a7     coreclr+0x974a2
21 00000019`12b7e3e0 00007ff8`f5960c2a     coreclr+0x971a7
22 00000019`12b7e480 00007ff8`f59600e1     coreclr+0x90c2a
23 00000019`12b7e880 00007ff8`f595fe78     coreclr+0x900e1
24 00000019`12b7e960 00007ff8`f5a2f485     coreclr+0x8fe78
25 00000019`12b7ea60 00007ff8`f5a2e143     coreclr!coreclr_set_error_writer+0x4115
26 00000019`12b7eb10 00007ff8`f5942c81     coreclr!coreclr_set_error_writer+0x2dd3
27 00000019`12b7eb50 00007ff8`f59b4c7c     coreclr+0x72c81
28 00000019`12b7ec90 00007ff8`f59b6322     coreclr+0xe4c7c
29 00000019`12b7edb0 00007ff8`f59b5ebe     coreclr+0xe6322
2a 00000019`12b7ee60 00007ff8`f59b52c7     coreclr+0xe5ebe
2b 00000019`12b7f130 00007ff8`f5a0a798     coreclr+0xe52c7
2c 00000019`12b7f230 00007ff9`08c1269f     coreclr!coreclr_execute_assembly+0xd8
2d 00000019`12b7f2d0 00007ff9`08c1297c     hostpolicy+0x2269f
2e 00000019`12b7f3f0 00007ff9`08c1328a     hostpolicy+0x2297c
2f 00000019`12b7f430 00007ff9`08c6da09     hostpolicy!corehost_main+0x15a
30 00000019`12b7f530 00007ff9`08c6ff86     hostfxr!hostfxr_close+0x23c9
31 00000019`12b7f610 00007ff9`08c7207c     hostfxr!hostfxr_close+0x4946
32 00000019`12b7f700 00007ff9`08c70553     hostfxr!hostfxr_close+0x6a3c
33 00000019`12b7f7b0 00007ff9`08c68390     hostfxr!hostfxr_close+0x4f13
34 00000019`12b7f8f0 00007ff6`c0f1f878     hostfxr!hostfxr_main_startupinfo+0xa0
35 00000019`12b7f9f0 00007ff6`c0f1fc86     testnet_exe+0xf878
36 00000019`12b7fba0 00007ff6`c0f211c8     testnet_exe+0xfc86
37 00000019`12b7fc10 00007ff9`1bd7dbe7     testnet_exe+0x111c8
38 00000019`12b7fc50 00007ff9`1d13fbec     KERNEL32!BaseThreadInitThunk+0x17
39 00000019`12b7fc80 00000000`00000000     ntdll!RtlUserThreadStart+0x2c

vfagent_net is the place where DeleteToken() is being called.

@dotnet-policy-service dotnet-policy-service bot added needs-further-triage Issue has been initially triaged, but needs deeper consideration or reconsideration and removed needs-author-action An issue or pull request that requires more info or actions from the author. labels Apr 7, 2025
@jkotas
Copy link
Member

jkotas commented Apr 7, 2025

Is there a way to get symbol info for dotnet binaries without building?

https://learn.microsoft.com/en-us/dotnet/core/diagnostics/dotnet-symbol

@tommcdon tommcdon added needs-author-action An issue or pull request that requires more info or actions from the author. and removed needs-further-triage Issue has been initially triaged, but needs deeper consideration or reconsideration labels Apr 28, 2025
Copy link
Contributor

This issue has been marked needs-author-action and may be missing some important information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-Diagnostics-coreclr needs-author-action An issue or pull request that requires more info or actions from the author. question Answer questions and provide assistance, not an issue with source code or documentation.
Projects
None yet
Development

No branches or pull requests

4 participants