From 298614bd91100887ede213095d3ae71d7bfa3400 Mon Sep 17 00:00:00 2001 From: Shay Rojansky Date: Sat, 22 Nov 2025 18:34:37 +0100 Subject: [PATCH 1/3] Bump version to 10.0.1 --- Directory.Build.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Directory.Build.props b/Directory.Build.props index de99b4fd8c..9a09fe1218 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,6 +1,6 @@  - 10.0.0 + 10.0.1 latest true enable From aa0e13893290dc3f9808ee7c010115c2b69491ac Mon Sep 17 00:00:00 2001 From: Nikita Kazmin Date: Tue, 9 Dec 2025 12:58:51 +0300 Subject: [PATCH 2/3] Throw OperationCancelledException with correct CancellationToken from Dns.GetHostAddressesAsync (#6364) Fixes #6362 (cherry picked from commit 19863c1562a48d2c7a2285091954988e60017b8a) --- src/Npgsql/Internal/NpgsqlConnector.cs | 4 ++-- test/Npgsql.Tests/MultipleHostsTests.cs | 7 +++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Npgsql/Internal/NpgsqlConnector.cs b/src/Npgsql/Internal/NpgsqlConnector.cs index 617ddcd03e..41a42950a7 100644 --- a/src/Npgsql/Internal/NpgsqlConnector.cs +++ b/src/Npgsql/Internal/NpgsqlConnector.cs @@ -1358,9 +1358,9 @@ async Task ConnectAsync(NpgsqlTimeout timeout, CancellationToken cancellationTok { ipAddresses = await Dns.GetHostAddressesAsync(Host, combinedToken).ConfigureAwait(false); } - catch (OperationCanceledException oce) when ( - oce.CancellationToken == combinedToken && !cancellationToken.IsCancellationRequested) + catch (OperationCanceledException) { + cancellationToken.ThrowIfCancellationRequested(); throw new TimeoutException(); } } diff --git a/test/Npgsql.Tests/MultipleHostsTests.cs b/test/Npgsql.Tests/MultipleHostsTests.cs index a98e0d60c2..b357417bb1 100644 --- a/test/Npgsql.Tests/MultipleHostsTests.cs +++ b/test/Npgsql.Tests/MultipleHostsTests.cs @@ -1137,10 +1137,13 @@ public async Task OpenConnection_when_canceled_throws_TaskCanceledException() { var builder = new NpgsqlDataSourceBuilder(ConnectionString); await using var dataSource = builder.BuildMultiHost(); - Assert.ThrowsAsync(async () => + using var cts = new CancellationTokenSource(); + cts.Cancel(); + var ex = Assert.ThrowsAsync(async () => { - await using var connection = await dataSource.OpenConnectionAsync(new CancellationToken(true)); + await using var connection = await dataSource.OpenConnectionAsync(cts.Token); }); + Assert.That(ex.CancellationToken, Is.EqualTo(cts.Token)); } [Test, IssueLink("https://github.com/npgsql/npgsql/issues/4181")] From 12d792ac2163596385152dcea5c68ba99769731f Mon Sep 17 00:00:00 2001 From: Nikita Kazmin Date: Thu, 18 Dec 2025 17:01:51 +0300 Subject: [PATCH 3/3] For COPY operations treat 0 as infinite timeout in addition to -1 (#6352) Fixes #6351 (cherry picked from commit 785b0b8f03c98231892caf9f1c9f50bc5a60bb3f) --- src/Npgsql/NpgsqlBinaryExporter.cs | 3 ++- src/Npgsql/NpgsqlBinaryImporter.cs | 6 ++++-- src/Npgsql/NpgsqlRawCopyStream.cs | 5 +++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/Npgsql/NpgsqlBinaryExporter.cs b/src/Npgsql/NpgsqlBinaryExporter.cs index 4828f0ecb1..65c616f496 100644 --- a/src/Npgsql/NpgsqlBinaryExporter.cs +++ b/src/Npgsql/NpgsqlBinaryExporter.cs @@ -7,6 +7,7 @@ using Npgsql.Internal; using Npgsql.Internal.Postgres; using NpgsqlTypes; +using InfiniteTimeout = System.Threading.Timeout; using static Npgsql.Util.Statics; namespace Npgsql; @@ -46,7 +47,7 @@ public sealed class NpgsqlBinaryExporter : ICancelable /// public TimeSpan Timeout { - set => _buf.Timeout = value; + set => _buf.Timeout = value > TimeSpan.Zero ? value : InfiniteTimeout.InfiniteTimeSpan; } Activity? _activity; diff --git a/src/Npgsql/NpgsqlBinaryImporter.cs b/src/Npgsql/NpgsqlBinaryImporter.cs index 6cd592dd06..60a1f09daf 100644 --- a/src/Npgsql/NpgsqlBinaryImporter.cs +++ b/src/Npgsql/NpgsqlBinaryImporter.cs @@ -8,6 +8,7 @@ using Npgsql.Internal; using Npgsql.Internal.Postgres; using NpgsqlTypes; +using InfiniteTimeout = System.Threading.Timeout; using static Npgsql.Util.Statics; namespace Npgsql; @@ -55,8 +56,9 @@ public TimeSpan Timeout { set { - _buf.Timeout = value; - _connector.ReadBuffer.Timeout = value; + var timeout = value > TimeSpan.Zero ? value : InfiniteTimeout.InfiniteTimeSpan; + _buf.Timeout = timeout; + _connector.ReadBuffer.Timeout = timeout; } } diff --git a/src/Npgsql/NpgsqlRawCopyStream.cs b/src/Npgsql/NpgsqlRawCopyStream.cs index 45cfdf825e..bbc641ff66 100644 --- a/src/Npgsql/NpgsqlRawCopyStream.cs +++ b/src/Npgsql/NpgsqlRawCopyStream.cs @@ -6,6 +6,7 @@ using Microsoft.Extensions.Logging; using Npgsql.BackendMessages; using Npgsql.Internal; +using InfiniteTimeout = System.Threading.Timeout; using static Npgsql.Util.Statics; #pragma warning disable 1591 @@ -42,12 +43,12 @@ public sealed class NpgsqlRawCopyStream : Stream, ICancelable public override int WriteTimeout { get => (int) _writeBuf.Timeout.TotalMilliseconds; - set => _writeBuf.Timeout = TimeSpan.FromMilliseconds(value); + set => _writeBuf.Timeout = value > 0 ? TimeSpan.FromMilliseconds(value) : InfiniteTimeout.InfiniteTimeSpan; } public override int ReadTimeout { get => (int) _readBuf.Timeout.TotalMilliseconds; - set => _readBuf.Timeout = TimeSpan.FromMilliseconds(value); + set => _readBuf.Timeout = value > 0 ? TimeSpan.FromMilliseconds(value) : InfiniteTimeout.InfiniteTimeSpan; } ///