Skip to content

Commit 615a90f

Browse files
akilinroji
authored andcommitted
Disable multiplexing when checking if db exists (#1579)
(cherry picked from commit e23739b)
1 parent 508391b commit 615a90f

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/EFCore.PG/Storage/Internal/NpgsqlDatabaseCreator.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,13 @@ public override bool Exists()
133133
{
134134
// When checking whether a database exists, pooling must be off, otherwise we may
135135
// attempt to reuse a pooled connection, which may be broken (this happened in the tests).
136-
var unpooledCsb = new NpgsqlConnectionStringBuilder(_connection.ConnectionString) { Pooling = false };
136+
// If Pooling is off, but Multiplexing is on - NpgsqlConnectionStringBuilder.Validate will throw,
137+
// so we turn off Multiplexing as well.
138+
var unpooledCsb = new NpgsqlConnectionStringBuilder(_connection.ConnectionString)
139+
{
140+
Pooling = false,
141+
Multiplexing = false
142+
};
137143
using var unpooledConn = ((NpgsqlConnection)_connection.DbConnection).CloneWith(unpooledCsb.ToString());
138144
using var _ = new TransactionScope(TransactionScopeOption.Suppress);
139145
unpooledConn.Open();
@@ -165,7 +171,13 @@ public override async Task<bool> ExistsAsync(CancellationToken cancellationToken
165171
{
166172
// When checking whether a database exists, pooling must be off, otherwise we may
167173
// attempt to reuse a pooled connection, which may be broken (this happened in the tests).
168-
var unpooledCsb = new NpgsqlConnectionStringBuilder(_connection.ConnectionString) { Pooling = false };
174+
// If Pooling is off, but Multiplexing is on - NpgsqlConnectionStringBuilder.Validate will throw,
175+
// so we turn off Multiplexing as well.
176+
var unpooledCsb = new NpgsqlConnectionStringBuilder(_connection.ConnectionString)
177+
{
178+
Pooling = false,
179+
Multiplexing = false
180+
};
169181
using var unpooledConn = ((NpgsqlConnection)_connection.DbConnection).CloneWith(unpooledCsb.ToString());
170182
using var _ = new TransactionScope(TransactionScopeOption.Suppress, TransactionScopeAsyncFlowOption.Enabled);
171183
await unpooledConn.OpenAsync(cancellationToken);

0 commit comments

Comments
 (0)