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
Deadlock when generating schema on parallel tasks ?? #778
Comments
I found another hack that works for my tests. By adding the following code, things run without any problem. var dynamicApisType = typeof(DynamicApis);
var fileTypeField = dynamicApisType.GetField("FileType", BindingFlags.NonPublic | BindingFlags.Static);
fileTypeField?.SetValue(null, null);
var directoryTypeField = dynamicApisType.GetField("DirectoryType", BindingFlags.NonPublic | BindingFlags.Static);
directoryTypeField?.SetValue(null, null);
var pathTypeField = dynamicApisType.GetField("PathType", BindingFlags.NonPublic | BindingFlags.Static);
pathTypeField?.SetValue(null, null); |
Returning false in FileExistsAsync essentially disables the whole XML Docs feature... it must be a problem with the locks... |
Can you provide a simple unit test to reproduce this problem? |
As I mentioned in the original post, I tried setting up a test project that would reproduce the error, but so far I haven't had any luck. I'll keep working my brain to see if I can figure out what the magical thing is to trigger this error. |
Maybe multiple projects/xml files? |
I did some more testing today using multiple projects, but so far no luck. The project where the problem surfaced is using a number of internal nuget packages, so I'm trying to distill it down to what is actually needed. |
If i update NJS with a possible fix, can you verify in your own project? |
Sure. |
if you make the change in a branch, I can get that and build against it and see how things behave. |
Can you try with the |
I'll try it out when I get into work tomorrow. |
I added the updated code, but it didn't have much effect. I've been exploring and trying things out for a couple of hours. I started by adding in a bunch of If I remove the locking code from That package is not compatible with the current frameworks supported by NJS. The changes I've made are in this patch file. |
I dont understand this, only the public methods are synchronized and all private methods aren't - also the synchronized public methods do not call other synchronized public methods (reclaim semaphore => deadlock). Maybe you can switch from WaitAsync() to Wait(), run your tests in debug mode, wait until it blocks, and examine the Debug > Windows > Threads window? |
I've updated the branch with your changes, except the uncommented sync code in |
My AsyncLock is just a wrapper around SemaphoreSlim, I dont want to reference another library just for this lock :-) - it must be something stupid... |
I've switched to this implementation, probably wont change much: http://applications.lt/awaiting-in-csharp-lock-block/ |
When I changed the code from |
What? That is really strange... |
Ok, I've switched to sync lock, can you verify with latest commit in the branch? Sync lock is fine for me, but still a little bothering because it makes a difference... |
Tried with the latest commit, and things work as expected. |
I have a .NET Core 2.1 application. In this I have code that calls
await JsonSchema4.FromTypeAsync<T>();
I also have 400+ tests, and for each of them the code that creates the schema is called. All my tests are asynchronous.
When running the tests through ReSharper, the majority of tests randomly hang until I stop test execution. If I run them one-by-one, things work fine, so I'm thinking deadlock might be an issue.
I downloaded the source code and built against that, then I started commenting out bits to see where things stopped working. I have tried creating a standalone project for this issue, but so far unsuccessful.
When digging around the code, I had to make two changes for it to work for me.
In XmlDocumentationExtensions.cs, there are a number of calls to
this I changed to
Since ASP .NET Core doesn't have a synchronization context, this baffles me a bit.
In DynamicApis.cs I had to change
I've also fired up Process Monitor so see if I could see anything related to file access, but haven't found anything.
The text was updated successfully, but these errors were encountered: