-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
IBackgroundTask services throw ObjectDisposedException because the YesSql ISession is disposed #16450
Comments
Yeah this needs some kind of repro but perhaps there's some exception happening earlier in BG task execution that gets swallowed but causes |
Way ahead of you, but somehow adding the extra log made the problem go away. Well, like I said it doesn't happen always. I will keep rerunning it to see if I can catch it with more logs. |
We triaged this issue and set the milestone according to the priority we think is appropriate (see the docs on how we triage and prioritize issues). This indicates when the core team may start working on it. However, if you'd like to contribute, we'd warmly welcome you to do that anytime. See our guide on contributions here. |
First step would be to understand what is the lifetime of a background task and how service provider scopes are managed in this case. That could hint at some bad patterns that dispose a Session where it shouldn't. |
I tried to understand how this ObjectDisposedException is possible. As far as I see, the session is only ever disposed through its parent container, as expected. As it is only ever hold by the active Because of that, it was my suspicion that something is not right with the ShellScopes lifetime. I thoroughly reviewed any possible call stack, but I only found one hypothetical case where a ShellScope gets disposed unexpectedly. The [Fact]
public async Task RecursiveUsingAsyncCallsMustNotDisposeScope()
{
await ShellHost.InitializeAsync();
var shellContext = await ShellHost.GetOrCreateShellContextAsync(
new ShellSettings()
{
Name = "Tenant1",
RequestUrlPrefix = "tenant1",
}
.AsUninitialized());
var rootScope = await shellContext.CreateScopeAsync();
await rootScope.UsingAsync(async (scope) =>
{
await (await ShellScope.CreateChildScopeAsync()).UsingAsync(async (childScope) =>
{
// Second UsingAsync() of the parent scope must not dispose the scope.
await scope.UsingAsync(innerRootScope => Task.CompletedTask);
});
// rootScope must not be disposed by calling UsingAsync() again if it is a recursive call.
Assert.False(scope.IsDisposed);
});
Assert.True(rootScope.IsDisposed);
} (Note: This requires to expose the This happens, because the I did not find this usage pattern anywhere in Orchards source, so I'm pretty sure this is not the actual issue. Also as the error does not occur every time, it is possibly some kind of a difficult to find race condition. But maybe we could guard against this case a little bit better. This may also be related to #16511, where a |
Describe the bug
Doesn't happen always, but when it happens all background tasks throw the following exception, so it may be something further up the line.
Orchard Core version
2.0.0-preview-18268
To Reproduce
I will update this if I find a reliable way to reproduce.
Expected behavior
Background tasks should not use disposed dependencies.
Logs and screenshots
A truncated set of examples from the app log:
The text was updated successfully, but these errors were encountered: