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

Sporadic AccessViolationException creating a thread using CreateThread #38654

Closed
vatsan-madhavan opened this issue Jul 1, 2020 · 4 comments
Closed
Labels
area-Interop-coreclr question Answer questions and provide assistance, not an issue with source code or documentation.

Comments

@vatsan-madhavan
Copy link
Member

Description

<< More likely just a question and not a bug report >>

Is there a known problem that could cause memory corruptions when calling CreateThread directly to create a thread (and passing a manaaged method as its ThreadProc) in a managed process?

--

When attempting to add P/Invoke sigs for CreateThread and allied functions (dotnet/pinvoke#463), I observed that my tests failed in the PR builds with AccessViolationException.

Initially I couldn't reproduce the problem locally, but with effort (i.e., with some modifications to the tests etc.) I was able to repro the problem locally as well in my own separate CI builds.

  • dotnet/pinvoke PR builds - repros always.
  • my personal PR builds - ~2/3 incidence
  • local/dev builds - highly variable; sometimes no repro and sometimes repros consistently.

I've only ever seen the problem repro under netfx TFM's. I've never been able to reproduce it under netstandard or netcoreapp TFM's. Another point of interest - if the threads are created suspended and never resumed, then all is well (no AV's, ever).

Configuration

  • The tests in question are here. .
  • Usually observed in net472 x86 runs only, and only sporadically. The repro is not consistent.
@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added area-System.Threading untriaged New issue has not been triaged by the area owner labels Jul 1, 2020
@vatsan-madhavan
Copy link
Member Author

/cc @AaronRobinsonMSFT

@AaronRobinsonMSFT AaronRobinsonMSFT added area-Interop-coreclr question Answer questions and provide assistance, not an issue with source code or documentation. and removed area-System.Threading untriaged New issue has not been triaged by the area owner labels Jul 1, 2020
@AaronRobinsonMSFT
Copy link
Member

AaronRobinsonMSFT commented Jul 1, 2020

@vatsan-madhavan I've never observed this. One important note is that the CreateRemoteThread() API is identical to CreateThread() when the current process is passed as the handle. I don't think that matters in this case but want to call it out. It would be helpful to see a DMP if possible. Do you know where the A/V is occurring? From the cursory look at the code it seems correct - albeit with a bit too much usage of recent C# sugar for my taste ;)

@jkotas
Copy link
Member

jkotas commented Jul 1, 2020

@jkotas jkotas closed this as completed Jul 1, 2020
@vatsan-madhavan
Copy link
Member Author

@jkotas thanks for the quick help!

@ghost ghost locked as resolved and limited conversation to collaborators Dec 8, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-Interop-coreclr 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