rails/activerecord/lib
Ian Candy 306ef99bbb Ensure transaction tracking finishes when reconnecting
We noticed a couple of spots where transaction tracking events
were potentially incorrect.

When the connection reconnects with `restore_transactions: true`,
we were keeping the original start time for the transaction. In this case
it seems more accurate to treat these as separte transactions where the first
one finishes as incomplete.

Instead of forcing the adapter to tell the transaction manager to
suspend (or `detach` or `lost`) the transactions, we can keep that
logic encapsulated inside of the Transaction class for when to broadcast
a finish event. This means that we won't capture a finish event if you
manually call `reconnect!` without `restore_transactions: true`, but
that might be worthy of the tradeoff since this is a rare use-case anyway.

We also start raising here if the TransactionInstrumenter receives `#start`
when already started, or `#finish` when not started. This ensures that we don't
quietly end up in any weird states.

When marking that a transaction is incomplete, we also want to check
that the transaction is materialized to avoid finishing our instrumentation
if it hasn't already started. Also added a test to simulate losing a connection
without ever materializing a transaction.

Co-authored-by: Daniel Colson <composerinteralia@github.com>
2023-10-04 19:35:22 -04:00
..
active_record Ensure transaction tracking finishes when reconnecting 2023-10-04 19:35:22 -04:00
arel Merge pull request #48095 from ippachi/triple-dot-range-unscope 2023-09-04 17:16:25 +09:00
rails/generators Simplify the implementation to register the correct source_path for the migration template 2023-05-24 22:54:12 +00:00
active_record.rb Change has_secure_token default to on: :initialize 2023-09-01 20:17:22 +00:00
arel.rb Fix a code block in the Arel documentation 2023-05-06 18:57:12 -07:00