-
Notifications
You must be signed in to change notification settings - Fork 32
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
Command.Result blocks indefinitely in xunit #104
Comments
@ForNeVeR thanks for reporting. I ran a quick script and I don't see any missing ConfigureAwaits, so I don't think that's the issue. Rather, under the hood In the meantime, I assume you could make your test async and replace with |
Yup, I'll be happy to take a look at it in a week or so.
It is not for all cases, but for me it is easy enough to convert to |
I'd suggest starting with a test that reproduces the issue. This should be possible by authoring a simple sync context that forces a single thread. |
@ForNeVeR just a thought: in your repro, what happens if you first greatly increase the max threadpool threads? |
Found another clue. These last two dudes in the "Scheduled" state: to me it looks like we are waiting for them. They are the continuations (or whatever's it called) of the And for whatever reason, they stay in this "Scheduled and waiting to run" state indefinitely.
Hard to say, yet.
Yep, I thought about that too. It's kinda tricky to figure out what exactly controls the thread pool size in xunit (after all, its settings being confusing is actually the core reason I opened the issue 😅), but I'm trying to figure that out. Not sure if it's the xunit threading settings and not of the system thread pool, though, but I'll experiment a bit. Ideally, xunit's threading should be unrelated because all the related code (be it system one or Medallion Shell) seems to call But perhaps it occupies the thread pool too much? But then that's confusing. AFAIK, the general behavior of the thread pool is to create new threads if a task hadn't been able to be scheduled for some time (like 500 ms by default?). Also, my computer has 16 cores, and there are there are total of 17 active tasks (and two in that weird "Scheduled" state). A coincidence? 🤔 |
I have changed |
Alright, this all task business seems to be just a red herring. What I found is that if I call So, it may be just a case of unclosed pipes from child processes that's being held open and thus causing the whole But I still cannot replicate this behavior in a simple console app, it only reproduces in xunit tests. WTF. |
I think I've found the difference. This is a child process of msbuild started from And this one is from a console app with exactly the same code: Everything's the same, but the latter shows Process in a job. It looks like they are doing something weird with job objects in one case, but don't do in another one, and that causes the difference. Perhaps when I do everything from a console app, then the initial UPD: I've tried running I am confused, but I believe that this puzzle has something to do with job objects; that's very likely. |
Reproduced in NUnit project as well. xunit is not involved. Most likely, this is due to the way the test host is started, and SDK starts its processes. I think that TODO
|
|
At least I've figured out that this issue is definitely unrelated to MedallionShell, so I've posted it to .NET SDK issue tracker: dotnet/sdk#34653 Still no idea whatever happens there, but let's at least free MedallionShell of this burden for now. |
Awesome. Thanks for the in-depth investigation @ForNeVeR |
I have been debugging this for a while and finally found a cause of my tests blocking on xunit.
I've been writing a simple xunit test:
This blocks indefinitely on
Result
(not onStandardOutput
!), even if I killdotnet build
and all the child processes manually.xunit is known for its sync context, so probably there's a
ConfigureAwait(false)
missing somewhere.(I wouldn't ask for this in general, but it's a good idea to use that if you provide a synchronous API.)
The text was updated successfully, but these errors were encountered: