From bfde75f3feb4c9f8f766df003de74aab8567df80 Mon Sep 17 00:00:00 2001 From: akilin Date: Mon, 16 Nov 2020 02:39:49 +0200 Subject: [PATCH] disable multiplexing when checking if db exists, because we also disable pooling --- .../Storage/Internal/NpgsqlDatabaseCreator.cs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/EFCore.PG/Storage/Internal/NpgsqlDatabaseCreator.cs b/src/EFCore.PG/Storage/Internal/NpgsqlDatabaseCreator.cs index 004c4b4ef..3508923b1 100644 --- a/src/EFCore.PG/Storage/Internal/NpgsqlDatabaseCreator.cs +++ b/src/EFCore.PG/Storage/Internal/NpgsqlDatabaseCreator.cs @@ -133,7 +133,13 @@ public override bool Exists() { // When checking whether a database exists, pooling must be off, otherwise we may // attempt to reuse a pooled connection, which may be broken (this happened in the tests). - var unpooledCsb = new NpgsqlConnectionStringBuilder(_connection.ConnectionString) { Pooling = false }; + // If Pooling is off, but Multiplexing is on - NpgsqlConnectionStringBuilder.Validate will throw, + // so we turn off Multiplexing as well. + var unpooledCsb = new NpgsqlConnectionStringBuilder(_connection.ConnectionString) + { + Pooling = false, + Multiplexing = false + }; using var unpooledConn = ((NpgsqlConnection)_connection.DbConnection).CloneWith(unpooledCsb.ToString()); using var _ = new TransactionScope(TransactionScopeOption.Suppress); unpooledConn.Open(); @@ -165,7 +171,13 @@ public override async Task ExistsAsync(CancellationToken cancellationToken { // When checking whether a database exists, pooling must be off, otherwise we may // attempt to reuse a pooled connection, which may be broken (this happened in the tests). - var unpooledCsb = new NpgsqlConnectionStringBuilder(_connection.ConnectionString) { Pooling = false }; + // If Pooling is off, but Multiplexing is on - NpgsqlConnectionStringBuilder.Validate will throw, + // so we turn off Multiplexing as well. + var unpooledCsb = new NpgsqlConnectionStringBuilder(_connection.ConnectionString) + { + Pooling = false, + Multiplexing = false + }; using var unpooledConn = ((NpgsqlConnection)_connection.DbConnection).CloneWith(unpooledCsb.ToString()); using var _ = new TransactionScope(TransactionScopeOption.Suppress, TransactionScopeAsyncFlowOption.Enabled); await unpooledConn.OpenAsync(cancellationToken);