-
Notifications
You must be signed in to change notification settings - Fork 10.3k
.NET Runtime Exception: ObjectDisposedException #4422
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
Comments
Do you have any idea what application code or event triggered this? This may need to be moved to https://github.com/dotnet/corefx/issues. |
@Tratcher Unfortunately not. I was hoping the stack trace would shed some light for you guys. Is it related to files and streams? We're using static files module but there are few actions that return 'File'. We also make extended use of web sockets. |
I am also getting this. Just start the app and refresh a web page a few times and get the System.ObjectDisposedException: 'The CancellationTokenSource has been disposed.' Nothing special about my web app as far as I can tell. I thought it was my separate hosted service, but I took that out and it still has the issue. |
Pretty sure this has nothing to do with it, but I removed app.UseStaticFiles() And I no longer have the issue. Could just be taking longer now, -or- it has something to do with the loading of css/js files.... |
OK.. Left in the 'UseStaticFiles' call but removed every js/css file being loaded. Still happened. But removed the 'UseStaticFiles' and after 10 min of constant refresh, no error. Usually it will happen within 4 or 5 page refreshes. So, now, what is the call to 'UseStaticFiles' doing that either causes it, or makes it happen? |
StaticFiles passes the HttpContext.RequestAborted CancellationToken to the read and write operations when it's serving a file. When you repeatedly press F5 some operations do not complete and get aborted. That's standard stuff and nothing has changed there in a long time. What might be new in 2.2: IIS applications are hosted in-process by default (as opposed to the prior out-of-process mode). It may be disposing of the RequestAborted CTS after canceling it. @jkotalik an aborted CTS should not be disposed, it causes races like this. Can you reproduce this if you edit the csproj and change it from InProcess to OutOfProcess? Or if you run only with Kestrel? Reguardless, there's a bug in CoreFx FileStreamCompletionSource about throwing exceptions on background threads that we should file. |
@Tratcher I think @sepehr1014 issue isn't related to inproc as the faulting exe is dotnet.exe. I looked at how we handle request aborted in InProc and from what I can tell, we don't call dispose on the cts after cancelling it. We can add some debug asserts to confirm. |
I'm actually running with Kestrel. And even waiting between refreshes of the page still causes the issue. So I don't think its the 'F5' aborting things. |
I did find what looks like a regression in FileStreamCompletionSource (need to confirm which versions), but that doesn't explain why the CTS was disposed. |
Hmm, the FileStreamCompletionSource happened in 2.1, not 2.2. There may be an additional change in Kestrel's CTS handling in 2.2... |
Looking at the changes linked above, the only thing that jumped out at me was the following:
And that's only because in ReleaseNativeResource() it calls cancellationRegistration.Dispose() and I am not sure what that call does to the internals of the original Token reference. Could it be doing something to the original token? I think I am just going in circles now. I traced back some discussions that may or my not be relevant.. https://github.com/dotnet/corefx/issues/14903 There was a mention in that thread about how Kestral does something different to handle an issue. Then once I dug into that I found this nugget:
So your guess that Kestrel does something different is valid. They have an entire extension class just for CancellationTokens. I switched over to IISExpress on my dev box and the issue seems to have gone away (another indication that its Kestrel). My end product is AM32 (Pi) which will be Kestrel, so I will do some testing there to see if its a platform specific thing. However, MY issues seems that it has diverged from the original issue because he WAS getting it to happen in IIS and not Kestrel. Could be that the UseStaticFiles on Kestrel just made it show up quicker and something else in IIS made it happen (but for the same underlying cause). |
Our app is behind IIS and we're not using InProc mode. (because of https://github.com/dotnet/core/blob/master/release-notes/2.2/2.2-known-issues.md) |
I'm running on Azure AppServices. I'm getting this issue when running InProc. Here's output from Kudo (although I tried to run 2.2.103 with self contained, no difference) :
My exception is as follows:
|
I'm experiencing the same issue, at least I'm quite sure it's related. I'm not able to reproduce it locally though, but no matter what I update of external nuget packages with these partial fixes, it seems to fail. I'm targeting full framework, net471. Currently running with Kestrel in service fabric. PackageReferences: <PackageReference Include="Microsoft.AspNetCore" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Http" Version="2.2.2" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.2" />
<PackageReference Include="Microsoft.AspNetCore.Routing" Version="2.2.2" />
<PackageReference Include="Microsoft.AspNetCore.Server.IIS" Version="2.2.2" />
<PackageReference Include="Microsoft.AspNetCore.Server.IISIntegration" Version="2.2.1" />
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets" Version="2.2.1" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.WebSockets" Version="2.2.1" />
<PackageReference Include="Microsoft.ServiceFabric.AspNetCore.Kestrel" Version="3.3.638" /> Normally I'd just reference AspNetCore.Mvc and AspNetCore, but in an effort to try to fix this I added updates direct references wherever I could find a newer one. StackTrace: I would assume that this possibly should have been fixed by #4447, but...I'm struggling with figuring out if this even has been released and which nuget package needs to be updated in that case. |
Well, i still find it weird that there is no v2.2.1 or v 2.2.2 of Microsoft.AspNetCore.Server.Kestrel.Core since the code at least has namespace aligned with that. Anyways, let's see if @halter73 can share some insight. Should at least be part of 2.2.2 release as far as I understand https://github.com/aspnet/AspNetCore/issues?utf8=%E2%9C%93&q=milestone%3A2.2.2+label%3Aservicing-approved |
Ultimately, only a fix for referencing CancellationTokenRegistration.Token after the CancellationTokenSource has been disposed made the patch. This prevents the process crash. We will need to rework #4447 to not potentially wait for user code under an internal lock before it can released. |
Glad to see this has been worked on by @jkotalik. Any ballpark guess regarding which version this will be shipped in? (Patch for .net core 2.2.x or .net core 3?) |
@abergs I think, in the current situation, it may be updated to Preview 5. Preview 4 will be released soon, and Preview 5 will take more than a month, or even two to three months. 2.2.4 just released a few days ago, 2.2.5 will take at least one month, so it seems. We have to wait at least one month, no matter which one... |
Right, preview5 is the next regular 3.0 release. We're also considering this for a patch in 2.2.6 or later. |
FWIW I have encountered this issue:
8 times in the past week, from a total traffic of roughly 3 million requests in that timeframe. This is on Azure App Service, .NET Core 2.2.4 and using ANCM InProcess. |
@Tratcher I couldn't see this issue mentioned in the 2.2.6 release notes. Did I miss it or will it not be released for 2.x? |
@jkotalik did we patch IIS for this? |
No, we didn't. I don't believe we patched Kestrel either though? |
I've seen the following exception 80 times in the last 7 days on a site that gets about 20K page views per week. Windows 2012 R2, dotnet hosting 2.2.6, InProcess.
|
I see that this issue was patched for 3.0. Will there be a patch 2.x line? |
I would be very curious if there are any updates on this one related to .NET Core 2.2.x users? @Tratcher @shirhatti |
There are two issues tracked in this thread.
We've re-worked the code to remove the chance of throwing an ODE in 3.0, however this doesn't meet the bar for a 2.2 backport since it's benign. We'd be happy to look into this again for 2.2 if anyone is actually experiencing a process crash due to this. |
@shirhatti I don't understand. For the first issue, when you say "This was fixed in CoreCLR.", what can I do to obtain that fix for my applications? When is that fix available for .NET Core 2.2 apps? |
@shirhatti The problem is that you may have solved that the process doesn't crash, but when this error happens the response from the API isn't returned and it clears out all the CORS headers too. So users of our API need to keep refreshing their application until the error doesn't come up. |
Why not? 3.0 is almost done, the latest previews have go-live (production) support licences. The final release will be out by the end of the month. |
Even before the fix in 3.0, the underlying connection must have already been aborted for the CancellationTokenSource backing HttpContext.RequestAborted to become disposed leading to an ObjectDisposedException. This means that clearing out the CORS headers should be a non-issue since the client could have never received said headers over a closed connection in the first place. If you are seeing a bunch of aborted requests and users need to keep refreshing the application to get a response, that points to a deeper issue. The ObjectDisposedException is merely a symptom of the already-aborted requests. I would look at info-level and higher ASP.NET core logs to see if there's any indication why the connections associated with the failing requests are being closed. |
This was fixed in 2.2.1 which was released way back in June 2018 |
I have a website where I get this error (with 2.2.2) irregularly. Sometimes multiple times a day, sometimes several days without it happening. Running in process Stacktrace: |
@jrmoreno1 can you try running 3.0? This issue should be resolved there. |
@jrmoreno1 I can confirm that I had the same issue and this is resolved in 3.0. I would still like to point out that there's so many breaking changes in 3.0 that it's not really an easy option for everyone to migrate just to resolve a pressing production issue. |
@jkotalik : one of the frustrating things about this is it only happens in production, not on the available test servers. So, no, I haven’t tried an upgrade to 3.0. We are planning on skipping 3.0 and going to 3.1 as it is supposed to come out in November. As an aside, you wouldn’t know if that was late or early November would you? |
Same here. But the expected final ship date is December 2019 as Richard has mentioned in this post: |
Isn't this fix going to be shipped in 2.2.8? At this stage it's quite hard to easily migrate to 3.0. (EF Core 3.0 disabling client validation being one of reasons) |
|
Is there some workaround or way to prevent this from spilling into the application log? We're using NLog together with ASP.NET Core 2.2.6 and currently this issue is spamming our logs and will potentially create customer support cases.
|
Describe the bug
After upgrading to ASP.NET Core 2.2, we frequently face this error and our website gets restarted. This happens once an hour or so. We had to target 2.1 again to fix this issue.
Here are the errors from event viewer (in the order they have occurred):
To Reproduce
Steps to reproduce the behavior:
Use SDK v2.2.100 with IIS on Windows Server 2016
Additional context
Add any other context about the problem here.
Include the output of
dotnet --info
The text was updated successfully, but these errors were encountered: