From d79ce87fba20c83c1b284e388adc0c080600f2fc Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Sat, 15 Apr 2017 23:41:01 +0300 Subject: [PATCH] Use serializable transaction for EPP domain:renew #430 --- app/controllers/epp/domains_controller.rb | 47 +++++++++++++---------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/app/controllers/epp/domains_controller.rb b/app/controllers/epp/domains_controller.rb index 675dcb90e..6962f42c8 100644 --- a/app/controllers/epp/domains_controller.rb +++ b/app/controllers/epp/domains_controller.rb @@ -105,29 +105,36 @@ class Epp::DomainsController < EppController balance_ok?('renew', period, period_unit) # loading pricelist - ActiveRecord::Base.transaction do - success = @domain.renew( - params[:parsed_frame].css('curExpDate').text, - period, period_unit - ) + begin + ActiveRecord::Base.transaction(isolation: :serializable) do + @domain.reload - if success - unless balance_ok?('renew', period, period_unit) - handle_errors - fail ActiveRecord::Rollback + success = @domain.renew( + params[:parsed_frame].css('curExpDate').text, + period, period_unit + ) + + if success + unless balance_ok?('renew', period, period_unit) + handle_errors + fail ActiveRecord::Rollback + end + + current_user.registrar.debit!({ + sum: @domain_pricelist.price.amount, + description: "#{I18n.t('renew')} #{@domain.name}", + activity_type: AccountActivity::RENEW, + log_pricelist_id: @domain_pricelist.id + }) + + render_epp_response '/epp/domains/renew' + else + handle_errors(@domain) end - - current_user.registrar.debit!({ - sum: @domain_pricelist.price.amount, - description: "#{I18n.t('renew')} #{@domain.name}", - activity_type: AccountActivity::RENEW, - log_pricelist_id: @domain_pricelist.id - }) - - render_epp_response '/epp/domains/renew' - else - handle_errors(@domain) end + rescue ActiveRecord::StatementInvalid => e + sleep rand / 100 + retry end end