Skip to content

Is AddDbContextPool supposed to release contexts from the pool? #35855

Open
@Steve887

Description

@Steve887

Question

I have a large context model, so I'm experimenting with context pooling.

My current setup is:

service.AddDbContextPool<AppDbContext>((provider, optionsBuilder) =>
{
    AppDbContextOptionsFactory.Get(optionsBuilder);
});

When I run my app, everything seems to work ok, except the active_dbcontexts seems to indicate the pooled dbcontexts are created but never released. Is this the expected behaviour for this?

Image

From debugging with EFCore symbols, it appears that AddDbContextPool uses a ScopedDbContextFactory that does not allow the lease to be released because IsStandalone is set to false.

EF Core version

9.0.0

Database provider

SqlServer

Target framework

.Net 9

Operating system

Windows 10

IDE

vs 2022

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions