You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Recently we added timeouts for our database with configuration like
Configuration from database.yml
connect_timeout: 5
read_timeout: 5
write_timeout: 5
checkout_timeout: 5
All values are in seconds
Steps to reproduce
When i run cap production deploy the deployment fails on migration step and gives error
Mysql2::Error::TimeoutError: Timeout waiting for a response from the last query.
Expected behavior
We want use MAX_EXECUTION_TIME=90000 rake db:migrate during our cap deploy and we will add a variable max_execution_time in our database.yml which will default to 5 seconds.
Additionally we could inject read_timeout also along with it if the max execution time doesn't work alone.
Actual behavior
We cannot control the injection of this variable because our Capfile uses capistrano/rails which will run rake db:migrate without maximum execution time and our migration could take much more time than our DB timeouts.
You could use the default env feature of Capistrano to prepend MAX_EXECUTION_TIME=90000 to every command, which would include rake db:migrate. Would that work?
You could use the default env feature of Capistrano to prepend MAX_EXECUTION_TIME=90000 to every command, which would include rake db:migrate. Would that work?
Can you add a debug statement in your app somewhere, maybe config/boot.rb to confirm that your app is actually receiving the environment as you expect?
Also does the capistrano log show that MAX_EXECUTION_TIME=90000 is being set when rake db:migrate is run?
Mysql timeouts are outside my area of expertise so I can't really help you with that part, but please let me know if capistrano is not setting the env as you expect.
Activity
mattbrictson commentedon Sep 14, 2019
You could use the default env feature of Capistrano to prepend
MAX_EXECUTION_TIME=90000to every command, which would includerake db:migrate. Would that work?piyush0609 commentedon Sep 16, 2019
Thanks @mattbrictson. Yeah that would work but recently i came across this https://capistranorb.com/documentation/advanced-features/overriding-capistrano-tasks/. So i am going ahead and using this
mattbrictson commentedon Sep 16, 2019
Great thanks for the follow up. Please close this issue once you get it working.
piyush0609 commentedon Sep 16, 2019
Sure @mattbrictson. Will close the issue once i test your implementation as well as mine.
piyush0609 commentedon Sep 18, 2019
Het @mattbrictson this didn't work. I still faced the timeout issue
mattbrictson commentedon Sep 18, 2019
Can you add a debug statement in your app somewhere, maybe
config/boot.rbto confirm that your app is actually receiving the environment as you expect?Also does the capistrano log show that
MAX_EXECUTION_TIME=90000is being set whenrake db:migrateis run?Mysql timeouts are outside my area of expertise so I can't really help you with that part, but please let me know if capistrano is not setting the env as you expect.
piyush0609 commentedon Oct 3, 2019
No
MAX_EXECUTION_TIME=90000was not being set whenrake db:migratewas ranmattbrictson commentedon Oct 3, 2019
Thanks for following up. I will dig into this some more to see if a bug is lurking in
:default_envor thedb:migratetask.piyush0609 commentedon Oct 3, 2019
I believe there is no issue with
default_envso don't worry about thatmattbrictson commentedon Oct 5, 2019
I tested this and it seems to work fine for me.
I configured capistrano as follows:
And modified the Rails app for debugging purposes:
When I run
cap production deployI see in the output:As you can see
MAX_EXECUTION_TIMEis printed so that means the environment variable is being received by the application.If I look at
log/capistrano.logI can see how it is being passed:mattbrictson commentedon Oct 5, 2019
Perhaps the problem is the
:default_envis being overwritten by another task in your capistrano setup? One way to troubleshoot is to run: