You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
But after this change (#3349), we had errors (reproduced below) and connection leaks (couldn't reproduce in the test).
Here's the repro:
publicsealedclassTestContext:DbContext{publicTestContext(DbContextOptions<TestContext>options):base(options){}}publicsealedclassConnectionOpeningInterceptor:DbConnectionInterceptor{publicoverrideasyncValueTask<InterceptionResult>ConnectionOpeningAsync(DbConnectionconnection,ConnectionEventDataeventData,InterceptionResultresult,CancellationTokencancellationToken=default){awaitconnection.OpenAsync(cancellationToken);returnInterceptionResult.Suppress();}}varservices=newServiceCollection();services.AddDbContext<TestContext>(options =>{options.UseNpgsql("connection string");options.AddInterceptors(newConnectionOpeningInterceptor());});awaitusingvarserviceProvider=services.BuildServiceProvider();varcontext=serviceProvider.GetRequiredService<TestContext>();varrelationalDatabaseCreator=context.GetService<IRelationalDatabaseCreator>();awaitrelationalDatabaseCreator.ExistsAsync();// okay, but doesn't close connectionawaitrelationalDatabaseCreator.ExistsAsync();// throws exception on the second invocation
I think the change slightly broke the semantics of the interceptor.
Before the change, The invocation of ConnectionOpening was always followed by the matching invocations of ConnectionOpened and ConnectionClosing or ConnectionDisposing if there were no errors.
But after the change, there is always one more invocation of ConnectionOpening
We removed the interceptor, so it doesn't necessarily need to be fixed for me, but I leave this issue as a future note.
The text was updated successfully, but these errors were encountered:
For other normal queries (e.g. await context.Database.SqlQueryRaw<int>($"SELECT 1").ToListAsync();), we get
a Connection is not open error if we suppress but don't open the connection.
a Connection already open error if we open the connection, but don't suppress.
So the interceptor must open the connection if and only if it suppresses.
If it doesn't suppress, EF opens the connection internally.
The connection is opened anyway, so EF closes it appropriately eventually.
However NpgsqlDatabaseCreator.Exist calls the ConnectionOpening (which opens the connection when suppressed), but it doesn't close the connection.
We somehow had a
DbConnectionInterceptor
that opens a connection onConnectionOpening
. I thought it could be doneIn EF Core,
ConnectionOpened
is invoked regardless ofIsSuppressed
value, so the interceptor should've opened the connection whenIsSuppressed
is true.https://github.com/dotnet/efcore/blob/6cacf97e1093965928d27e99a7b3f90d25c0b01b/src/EFCore.Relational/Storage/RelationalConnection.cs#L758-L767
But after this change (#3349), we had errors (reproduced below) and connection leaks (couldn't reproduce in the test).
Here's the repro:
I think the change slightly broke the semantics of the interceptor.
Before the change, The invocation of
ConnectionOpening
was always followed by the matching invocations ofConnectionOpened
andConnectionClosing
orConnectionDisposing
if there were no errors.But after the change, there is always one more invocation of
ConnectionOpening
We removed the interceptor, so it doesn't necessarily need to be fixed for me, but I leave this issue as a future note.
The text was updated successfully, but these errors were encountered: