Repository navigation
Reset connection when closing within TransactionScope - #6424
Conversation
There was a problem hiding this comment.
Pull request overview
This pull request attempts to fix issue #3735 by resetting pooled connections when they are closed within a TransactionScope. The goal is to ensure that when a connection is closed and then reopened within the same TransactionScope, temporary tables, sequences, and other session state are reset, even though the same physical connection is reused.
Changes:
- Added a new
ResetWithinEnlistedTransaction()method to reset connector state when closing within an enlisted transaction - Updated
NpgsqlConnection.CloseAsync()to call the new reset method before adding the connector to the pending enlisted list - Added documentation comments explaining the new reset behavior
- Added a test case to verify that temp tables are properly discarded when reusing connections within a TransactionScope
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| test/Npgsql.Tests/SystemTransactionTests.cs | Added test to verify temp tables are reset when reusing connections in TransactionScope |
| src/Npgsql/NpgsqlConnection.cs | Updated connection close logic to reset connector before adding to enlisted pending list |
| src/Npgsql/Internal/NpgsqlConnector.cs | Added ResetWithinEnlistedTransaction() method and updated GenerateResetMessage() documentation |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
689ce47 to
93dbcbe
Compare
| } | ||
|
|
||
| [MemberNotNull(nameof(_resetWithoutDeallocateMessage))] | ||
| void GenerateResetMessage() |
There was a problem hiding this comment.
@roji do you think it might make sense to move _resetWithoutDeallocateMessage to the data source/database info, rather than cache per each connector? Not in this pr of course.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
553b6db to
bfa4f45
Compare
…metry (#347) Updated [Npgsql.EntityFrameworkCore.PostgreSQL](https://github.com/npgsql/efcore.pg) from 10.0.3 to 10.0.4. <details> <summary>Release notes</summary> _Sourced from [Npgsql.EntityFrameworkCore.PostgreSQL's releases](https://github.com/npgsql/efcore.pg/releases)._ ## 10.0.4 [Milestone issue](https://github.com/npgsql/efcore.pg/milestone/79?closed=1) ## What's Changed * [10.0] Backport regex operand parentheses fix by @roji in npgsql/efcore.pg#3928 * [10.0] Remove unused SSL setup from Windows CI by @roji in npgsql/efcore.pg#3931 * [10.0] Backport unnest type mapping inference fix by @roji in npgsql/efcore.pg#3945 * [10.0] Truncate sub-microsecond ticks when formatting TimeSpan as interval by @roji in npgsql/efcore.pg#3947 * [10.0] Preserve row value type mappings when rewriting expressions by @roji in npgsql/efcore.pg#3954 * [10.0] Fix Last() on primitive collections returning the first array element by @roji in npgsql/efcore.pg#3956 * [10.0] Configure row value regression tuple mapping locally by @roji in npgsql/efcore.pg#3960 * [10.0] Update EF Core and other dependencies by @roji in npgsql/efcore.pg#3963 * [10.0] Fix collection conversion with nullable element converters (#3965) by @roji in npgsql/efcore.pg#3967 * [10.0] Fix Contains on an object collection over a value-converted column (#3961) by @roji in npgsql/efcore.pg#3970 * [10.0] Fix tsvector metadata cast for IReadOnlyList by @roji in npgsql/efcore.pg#3986 * [10.0] Fix explicit column types for owned JSON collections by @roji in npgsql/efcore.pg#3989 * [10.0] Prevent PadLeft/PadRight from truncating shorter target widths by @roji in npgsql/efcore.pg#3993 * [10.0] Fix array type inference for mixed collection types by @roji in npgsql/efcore.pg#3996 * [10.0] Fix null checks on unbounded NodaTime Interval bounds by @roji in npgsql/efcore.pg#4002 * [10.0] Backport fix for null propagation in date/time intervals by @roji in npgsql/efcore.pg#4015 * [10.0] Support System.Text.Json serialization of LTree by @roji in npgsql/efcore.pg#4010 * [10.0] Preserve array element converters with explicit column types by @roji in npgsql/efcore.pg#4011 * [10.0] Fix repeated seed-data updates for list properties by @roji in npgsql/efcore.pg#4029 * [10.0] Fix BCE NodaTime SQL literal formatting by @roji in npgsql/efcore.pg#4027 * [10.0] Preserve inherited HiLo sequences in model snapshots by @roji in npgsql/efcore.pg#4032 * [10.0] Fix date/time mapping round-tripping and cloning by @roji in npgsql/efcore.pg#4037 * [10.0] Fix Regex.Replace to replace all matches by @roji in npgsql/efcore.pg#4041 * [10.0] Restore raw JSON byte array mapping by @roji in npgsql/efcore.pg#4044 * [10.0] Translate ToString() on string expressions by @roji in npgsql/efcore.pg#4050 * [10.0] Own newly cloned connections by @roji in npgsql/efcore.pg#4056 * [10.0] Fix type mapping for derived tsquery parameters by @roji in npgsql/efcore.pg#4060 * [10.0] Fix precision-only numeric migration snapshot churn by @roji in npgsql/efcore.pg#4070 * [10.0] Fix byte-array projections from JSON collections by @roji in npgsql/efcore.pg#4073 * [10.0] Fix tsvector columns over JSON-mapped navigations/complex properties by @roji in npgsql/efcore.pg#4076 * [10.0] Fix hstore SQL literal generation for null and escaped values by @roji in npgsql/efcore.pg#4106 * [10.0] Fix TimeOnly.IsBetween for midnight-spanning ranges by @roji in npgsql/efcore.pg#4131 * [10.0] Parenthesize the item of ANY/ALL when its precedence requires it by @roji in npgsql/efcore.pg#4132 * [10.0] Format storage parameter values with the invariant culture by @roji in npgsql/efcore.pg#4133 **Full Changelog**: npgsql/efcore.pg@v10.0.3...v10.0.4 Commits viewable in [compare view](npgsql/efcore.pg@v10.0.3...v10.0.4). </details> Pinned [Npgsql.OpenTelemetry](https://github.com/npgsql/npgsql) at 11.0.0. <details> <summary>Release notes</summary> _Sourced from [Npgsql.OpenTelemetry's releases](https://github.com/npgsql/npgsql/releases)._ ## 11.0.0 See the [release notes](https://www.npgsql.org/doc/release-notes/11.0.html). The full list of changes is available [here](https://github.com/npgsql/npgsql/milestone/132?closed=1). ## What's Changed * Bump GitHubActionsTestLogger from 2.4.1 to 3.0.1 by @dependabot[bot] in npgsql/npgsql#6353 * Docs: clarify NpgsqlParameterCollection.Add(object) requires NpgsqlParameter by @nimanikoo in npgsql/npgsql#6342 * Bump actions/setup-dotnet from 5.0.0 to 5.0.1 by @dependabot[bot] in npgsql/npgsql#6355 * Bump Scriban.Signed from 6.5.1 to 6.5.2 by @dependabot[bot] in npgsql/npgsql#6356 * Fix flaky test PostgresType by @vonzshik in npgsql/npgsql#6354 * Drop net8.0 and net9.0 TFMs by @roji in npgsql/npgsql#6358 * Bump BenchmarkDotNet from 0.15.6 to 0.15.8 by @dependabot[bot] in npgsql/npgsql#6361 * Bump NUnit3TestAdapter from 5.2.0 to 6.0.0 by @dependabot[bot] in npgsql/npgsql#6365 * Throw OperationCancelledException with correct CancellationToken from Dns.GetHostAddressesAsync by @vonzshik in npgsql/npgsql#6364 * Bump dotnet logging and DI dependencies by @roji in npgsql/npgsql#6371 * Bump NodaTime from 3.2.2 to 3.2.3 by @dependabot[bot] in npgsql/npgsql#6375 * Bump actions/upload-artifact from 5 to 6 by @dependabot[bot] in npgsql/npgsql#6377 * Bump actions/cache from 4 to 5 by @dependabot[bot] in npgsql/npgsql#6378 * For COPY operations treat 0 as infinite timeout in addition to -1 by @vonzshik in npgsql/npgsql#6352 * Bump NUnit3TestAdapter from 6.0.0 to 6.0.1 by @dependabot[bot] in npgsql/npgsql#6387 * Fix reading numerics as BigInteger by @vonzshik in npgsql/npgsql#6385 * Add empty permissions block in Github Actions configs (#3694) by @roji in npgsql/npgsql#6392 * Fix test timeout_during_authentication by @vonzshik in npgsql/npgsql#6388 * Fix retrieving sequence file for hanging tests by @vonzshik in npgsql/npgsql#6397 * Fix reading BigInteger with composites by @vonzshik in npgsql/npgsql#6390 * Do not include password in data source name with Persist Security Info=true by @roji in npgsql/npgsql#6395 * [Tests] Remove npgsqldbtype passing and rename related flag by @NinoFloris in npgsql/npgsql#6305 * Year++ by @vonzshik in npgsql/npgsql#6402 * Bump NodaTime from 3.2.3 to 3.3.0 by @dependabot[bot] in npgsql/npgsql#6403 * Bump NUnit3TestAdapter from 6.0.1 to 6.1.0 by @dependabot[bot] in npgsql/npgsql#6405 * Bump some dependencies by @roji in npgsql/npgsql#6411 * Bump actions/setup-dotnet from 5.0.1 to 5.1.0 by @dependabot[bot] in npgsql/npgsql#6412 * Bump Microsoft.Data.SqlClient from 6.1.3 to 6.1.4 by @dependabot[bot] in npgsql/npgsql#6414 * Bump OpenTelemetry.Api from 1.14.0 to 1.15.0 by @dependabot[bot] in npgsql/npgsql#6420 * Bump OpenTelemetry and OpenTelemetry.Exporter.InMemory by @dependabot[bot] in npgsql/npgsql#6421 * Improve fallback handling for GSS session encryption when native library is missing by @vonzshik in npgsql/npgsql#6422 * Fix wrapping OperationCancelledException for physical open by @vonzshik in npgsql/npgsql#6425 * Fix reusing NpgsqlBatch with auto prepare by @vonzshik in npgsql/npgsql#6433 * Do not clear pool while establishing connection if we'll retry it by @vonzshik in npgsql/npgsql#6431 * Fix for retrieving column metadata for Postgres < 10 by @KeltorHD in npgsql/npgsql#6438 * Some SQL query cleanup by @roji in npgsql/npgsql#6439 * Reset connection when closing within TransactionScope by @roji in npgsql/npgsql#6424 * Fix per instance nullability converter resolver info code by @NinoFloris in npgsql/npgsql#6435 * Bump Microsoft.SourceLink.GitHub from 10.0.102 to 10.0.103 by @dependabot[bot] in npgsql/npgsql#6445 * Bump Microsoft.Extensions.DependencyInjection.Abstractions from 10.0.2 to 10.0.3 by @dependabot[bot] in npgsql/npgsql#6441 * Bump extensions versions to 10.0.3 by @roji in npgsql/npgsql#6448 * Bump Scriban.Signed from 6.5.2 to 6.5.3 by @dependabot[bot] in npgsql/npgsql#6455 * [Tests] Fully rework type mapping assertion helpers by @NinoFloris in npgsql/npgsql#6314 * Bump Microsoft.NET.Test.Sdk from 18.0.1 to 18.3.0 by @dependabot[bot] in npgsql/npgsql#6460 * Bump actions/upload-artifact from 6 to 7 by @dependabot[bot] in npgsql/npgsql#6461 ... (truncated) ## 10.0.4 [Release milestone](https://github.com/npgsql/npgsql/milestone/139?closed=1) **Full Changelog**: npgsql/npgsql@v10.0.3...v10.0.4 Commits viewable in [compare view](npgsql/npgsql@v10.0.3...v11.0.0). </details> Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Rene Bentes Pinto <[email protected]>
Fixes #3735