Previously closing a connection within a TransactionScope triggered an
automatic promotion to a prepared transaction. Since by default Postgres
disables these, this made the TransactionScope unusable for many cases.
This is reproduced in
SystemTransactionTests.SimpleTransactionScopeWithImplicitEnlist, which was
failing in stock Postgres installations.
Instead of promoting, we now postpone the close until the (local)
transaction is terminated, i.e. until the TransactionScope ends.
- Removed the previous "postponed close" state on Connection, which allowed for partial connection
reuse within an ambient transaction (see npgsql#8 and
discussion on the list).
- When a Connection is closed while a TransactionScope is still active, its connector is detached
and returned to the pool, but specially marked as AvailableWithTransaction. Any subsequent
Connection within the same transaction and connection string will now preferably be attached to
that connector, preventing escalation to prepared transactions.
- When an ambient transaction completes, all the connectors involved it in are notified. If a
connector is detached (i.e. its connection has already been closed), it is returned to the pool
and marked as Available.
- A similar flow has been implemented for non-pooled connections/connectors.
- The above required a refactor of Connector, Connection and some associated classes. In particular,
to allow connections to be smoothly detached and reattached to connectors, many Npgsql components
now references the connector instead of the connection, and the connection has been made as bare
a frontend as possible.
- SSL callbacks are now always registered just before Connector.Open(), and removed right