Created
October 24, 2017 15:58
-
-
Save gregblake/7ec8972c134201184288176600dddff1 to your computer and use it in GitHub Desktop.
production_training_timeout.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| MYSQL_WAIT_TIMEOUT_MAX = 2147483 | |
| def test_connection(extra_conf = {}) | |
| conf = { | |
| :host => "HOST_NAME", | |
| :username => "USER_NAME", | |
| :password => "PASSWORD", | |
| :database => "DATABASE_NAME", | |
| :adapter => "mysql2" | |
| } | |
| ActiveRecord::Base.establish_connection(conf.merge(extra_conf)) | |
| puts ActiveRecord::Base.connection.execute("SHOW VARIABLES LIKE \"wait_timeout\"").to_a.join(" : ") | |
| seconds_to_sleep = [ 60, 120, 180, 240, 300, 360] | |
| seconds_to_sleep.each do |seconds| | |
| sleep seconds | |
| puts ActiveRecord::Base.connection.active? ? "Connection up !" : "Connection lost !" | |
| end | |
| end | |
| # After more than 5 minutes of inactivity, the ActiveRecord connection becomes disconnected, which results in the "MySQL Server Has Gone Away" error": | |
| irb(main):058:0> test_connection(:wait_timeout => MYSQL_WAIT_TIMEOUT_MAX) | |
| wait_timeout : 2147483 | |
| Connection up ! | |
| Connection up ! | |
| Connection up ! | |
| Connection up ! | |
| Connection up ! | |
| Connection lost ! | |
| => [60, 120, 180, 240, 300, 360] |
Author
Author
I just tested it again on training-nitro-task1 with the Rails environment training_production, after Johnathan Rodgers made changes related to this bug.
The connection did not time out after more than 5 minutes of inactivity. Here are the results of the test script:
irb(main):025:0> test_connection(:wait_timeout => MYSQL_WAIT_TIMEOUT_MAX)
wait_timeout : 2147483
Connection up !
Connection up !
Connection up !
Connection up !
Connection up !
Connection up !
=> [60, 120, 180, 240, 300, 360]
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
On my development environment, the connection remains after 5 minutes of inactivity:
Here's the same test on demo21:
And on production: