Skip to content

Commit

Permalink
Fix executing connectionless command on NpgsqlDataSource with multipl…
Browse files Browse the repository at this point in the history
…exing (#4841)

Fixes #4840

(cherry picked from commit ad7dee8)
  • Loading branch information
vonzshik committed Feb 10, 2023
1 parent babc9c7 commit 7a5c449
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Npgsql/MultiplexingDataSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ async Task MultiplexingWriteLoop()
}

connector = await OpenNewConnector(
command.Connection!,
command.InternalConnection!,
new NpgsqlTimeout(TimeSpan.FromSeconds(Settings.Timeout)),
async: true,
CancellationToken.None);
Expand Down
20 changes: 20 additions & 0 deletions test/Npgsql.Tests/DataSourceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -260,4 +260,24 @@ public async Task As_DbDataSource([Values] bool async)
? await command.ExecuteScalarAsync()
: command.ExecuteScalar(), Is.EqualTo(1));
}

[Test, IssueLink("https://github.com/npgsql/npgsql/issues/4840")]
public async Task Multiplexing_connectionless_command_open_connection()
{
var csb = new NpgsqlConnectionStringBuilder(ConnectionString)
{
Multiplexing = true
};
await using var dataSource = NpgsqlDataSource.Create(csb.ConnectionString);

await using var conn = await dataSource.OpenConnectionAsync();
await using var _ = await conn.BeginTransactionAsync();

await using var command = dataSource.CreateCommand();
command.CommandText = "SELECT 1";

await using var reader = await command.ExecuteReaderAsync();
Assert.True(reader.Read());
Assert.That(reader.GetInt32(0), Is.EqualTo(1));
}
}

0 comments on commit 7a5c449

Please sign in to comment.