TimeOut with transaction block rails
heroku, ruby, ruby-on-rails, transactions
Solution
When a Rack timeout happens, any transaction in process will be rolled back, but transactions that have already been committed will, of course remain committed. You should not have to worry about it.
Once you start a database transaction, it will eventually either be committed or rolled back. Those are the only two possibilities for ending a transaction. When you commit the transaction, you are saying that you want those changes to be saved regardless of what happens next. If you do not commit the transaction, the database will automatically rollback the transaction once it gets into any state where the transaction cannot move forward, such as a broken network connection.
`ActiveRecord` automatically commits the transaction when the `ActiveRecord::Base.transaction do` block exits normally. Abnormal exits may cause `ActiveRecord` to issue a `ROLLBACK` command to the database, which is efficient and good practice and returns the connection to a ready state, but it is not strictly necessary, because unless the transaction is explicitly committed, the database will eventually automatically roll it back.
Problem
As my understanding, if we have any code inside this transaction and when it happens any error with (save!, ...) in that block the entire code will revert, here the problem is if any timeout (rack timeout = 12) happens in this block. ``` def create ActiveRecord::Base.transaction do // timeout happens end end ``` How can we rollback a code with a transaction when a `Rack::Timeout` occurs?