ActiveRecord transactions & thread safety

21 views
Skip to first unread message

Alexey Chernenkov

unread,
Jun 3, 2014, 12:32:57 AM6/3/14
to rubyonra...@googlegroups.com
My question is about AR transactions feature. Is it thread safe?
Is it safe to use both `ActiveRecord::Base.transaction do ...` and `Account.transaction do ...` statements?

I plan to use Puma as web server, and Sidekiq for background processing.
Is there some tricks I should know about?

Thanks!

Frederick Cheung

unread,
Jun 3, 2014, 3:11:18 AM6/3/14
to rubyonra...@googlegroups.com
On Tuesday, June 3, 2014 5:32:57 AM UTC+1, Alexey Chernenkov wrote:
> My question is about AR transactions feature. Is it thread safe?
> Is it safe to use both `ActiveRecord::Base.transaction do ...` and `Account.transaction do ...` statements?
>
>

It should be - a connection is only ever used by 1 thread at a time (and unless you have configured Account to use a separate connection then AR won't be default create nested transactions/save points )If you could show in more detail what you are doing then a more considered reply might be possible.

Fred

Reply all
Reply to author
Forward
0 new messages