module Sequel::TransactionConnectionValidator

  1. lib/sequel/extensions/transaction_connection_validator.rb

Methods

Public Instance

  1. transaction

Public Instance methods

transaction(opts=OPTS)

Rescue disconnect errors raised when beginning a new transaction. If there is a disconnnect error, it should be safe to retry the transaction using a new connection, as we haven’t yielded control to the user yet.

[show source]
   # File lib/sequel/extensions/transaction_connection_validator.rb
38 def transaction(opts=OPTS)
39   super
40 rescue DisconnectRetry => e
41   if synchronize(opts[:server]){|conn| conn.equal?(e.connection)}
42     # If retrying would use the same connection, that means the
43     # connection was not removed from the pool, which means the caller has
44     # already checked out the connection, and retrying will not be successful.
45     # In this case, we can only reraise the exception.
46     raise e.database_error
47   end
48 
49   num_retries ||= 0 
50   num_retries += 1
51   retry if num_retries < 5
52 
53   raise e.database_error
54 end