-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FIX: Falling back to primary PG server not reliable on Rails 7.1
This commit drops the reliance on `ActiveRecord::ConnectionAdapters::PostgreSQLAdapter#active?` in favor or using `ActiveRecord::ConnectionAdatpers::PostgreSQLAdatper#execute` to check if the app can connect to the primary PG server. This is because `ActiveRecord::ConnectionAdapters::PostgreSQLAdapter#active?` was changed in Rails 7.1 to return `false` if the connection has not be used to do something meaningful. Ref: rails/rails@8551e64. Due to this change, our fallback to primary checker will keep thinking that the primary PG server is down. Note that before Rails 7.1, `ActiveRecord::ConnectionAdapters::PostgreSQLAdapter#active?` will always execute a fake query to check if the query can be executed. Instead of relying on ActiveRecord's internal API, we will instead rely on `ActiveRecord::ConnectionAdapters::PostgreSQLAdapter#execute` to execute a blank query as our means of verifying if the PG server is up and ready to receive connections. This commit also updates the ActiveRecord tests to be more reliable by reducing the Unicorn worker processes to 1 so that we don't have to rely on flooding the app with requests to get all the Unicorn processes to failover/fallback. Co-authored-by: Loïc Guitaut <loic@discourse.org>
- Loading branch information
Showing
20 changed files
with
747 additions
and
92 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,4 +16,3 @@ | |
*.rdb | ||
|
||
*.gem | ||
Gemfile.lock |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
--color | ||
--require spec_helper | ||
--format documentation | ||
--order random |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,205 @@ | ||
PATH | ||
remote: . | ||
specs: | ||
rails_failover (2.1.1) | ||
activerecord (>= 6.1, < 8.0) | ||
concurrent-ruby | ||
railties (>= 6.1, < 8.0) | ||
|
||
GEM | ||
remote: https://rubygems.org/ | ||
specs: | ||
actionpack (7.1.3.4) | ||
actionview (= 7.1.3.4) | ||
activesupport (= 7.1.3.4) | ||
nokogiri (>= 1.8.5) | ||
racc | ||
rack (>= 2.2.4) | ||
rack-session (>= 1.0.1) | ||
rack-test (>= 0.6.3) | ||
rails-dom-testing (~> 2.2) | ||
rails-html-sanitizer (~> 1.6) | ||
actionview (7.1.3.4) | ||
activesupport (= 7.1.3.4) | ||
builder (~> 3.1) | ||
erubi (~> 1.11) | ||
rails-dom-testing (~> 2.2) | ||
rails-html-sanitizer (~> 1.6) | ||
activemodel (7.1.3.4) | ||
activesupport (= 7.1.3.4) | ||
activerecord (7.1.3.4) | ||
activemodel (= 7.1.3.4) | ||
activesupport (= 7.1.3.4) | ||
timeout (>= 0.4.0) | ||
activesupport (7.1.3.4) | ||
base64 | ||
bigdecimal | ||
concurrent-ruby (~> 1.0, >= 1.0.2) | ||
connection_pool (>= 2.2.5) | ||
drb | ||
i18n (>= 1.6, < 2) | ||
minitest (>= 5.1) | ||
mutex_m | ||
tzinfo (~> 2.0) | ||
ast (2.4.2) | ||
base64 (0.2.0) | ||
bigdecimal (3.1.8) | ||
builder (3.3.0) | ||
byebug (11.1.3) | ||
concurrent-ruby (1.3.3) | ||
connection_pool (2.4.1) | ||
crass (1.0.6) | ||
diff-lcs (1.5.1) | ||
drb (2.2.1) | ||
erubi (1.13.0) | ||
i18n (1.14.5) | ||
concurrent-ruby (~> 1.0) | ||
io-console (0.7.2) | ||
irb (1.13.2) | ||
rdoc (>= 4.0.0) | ||
reline (>= 0.4.2) | ||
json (2.7.2) | ||
language_server-protocol (3.17.0.3) | ||
loofah (2.22.0) | ||
crass (~> 1.0.2) | ||
nokogiri (>= 1.12.0) | ||
minitest (5.24.1) | ||
mutex_m (0.2.0) | ||
nokogiri (1.16.6-aarch64-linux) | ||
racc (~> 1.4) | ||
nokogiri (1.16.6-arm-linux) | ||
racc (~> 1.4) | ||
nokogiri (1.16.6-arm64-darwin) | ||
racc (~> 1.4) | ||
nokogiri (1.16.6-x86-linux) | ||
racc (~> 1.4) | ||
nokogiri (1.16.6-x86_64-darwin) | ||
racc (~> 1.4) | ||
nokogiri (1.16.6-x86_64-linux) | ||
racc (~> 1.4) | ||
parallel (1.25.1) | ||
parser (3.3.3.0) | ||
ast (~> 2.4.1) | ||
racc | ||
pg (1.5.6) | ||
prettier_print (1.2.1) | ||
psych (5.1.2) | ||
stringio | ||
racc (1.8.0) | ||
rack (3.1.6) | ||
rack-session (2.0.0) | ||
rack (>= 3.0.0) | ||
rack-test (2.1.0) | ||
rack (>= 1.3) | ||
rackup (2.1.0) | ||
rack (>= 3) | ||
webrick (~> 1.8) | ||
rails-dom-testing (2.2.0) | ||
activesupport (>= 5.0.0) | ||
minitest | ||
nokogiri (>= 1.6) | ||
rails-html-sanitizer (1.6.0) | ||
loofah (~> 2.21) | ||
nokogiri (~> 1.14) | ||
railties (7.1.3.4) | ||
actionpack (= 7.1.3.4) | ||
activesupport (= 7.1.3.4) | ||
irb | ||
rackup (>= 1.0.0) | ||
rake (>= 12.2) | ||
thor (~> 1.0, >= 1.2.2) | ||
zeitwerk (~> 2.6) | ||
rainbow (3.1.1) | ||
rake (12.3.3) | ||
rdoc (6.7.0) | ||
psych (>= 4.0.0) | ||
redis (4.8.1) | ||
regexp_parser (2.9.2) | ||
reline (0.5.9) | ||
io-console (~> 0.5) | ||
rexml (3.3.1) | ||
strscan | ||
rspec (3.13.0) | ||
rspec-core (~> 3.13.0) | ||
rspec-expectations (~> 3.13.0) | ||
rspec-mocks (~> 3.13.0) | ||
rspec-core (3.13.0) | ||
rspec-support (~> 3.13.0) | ||
rspec-expectations (3.13.1) | ||
diff-lcs (>= 1.2.0, < 2.0) | ||
rspec-support (~> 3.13.0) | ||
rspec-mocks (3.13.1) | ||
diff-lcs (>= 1.2.0, < 2.0) | ||
rspec-support (~> 3.13.0) | ||
rspec-support (3.13.1) | ||
rubocop (1.64.1) | ||
json (~> 2.3) | ||
language_server-protocol (>= 3.17.0) | ||
parallel (~> 1.10) | ||
parser (>= 3.3.0.2) | ||
rainbow (>= 2.2.2, < 4.0) | ||
regexp_parser (>= 1.8, < 3.0) | ||
rexml (>= 3.2.5, < 4.0) | ||
rubocop-ast (>= 1.31.1, < 2.0) | ||
ruby-progressbar (~> 1.7) | ||
unicode-display_width (>= 2.4.0, < 3.0) | ||
rubocop-ast (1.31.3) | ||
parser (>= 3.3.1.0) | ||
rubocop-capybara (2.21.0) | ||
rubocop (~> 1.41) | ||
rubocop-discourse (3.8.1) | ||
activesupport (>= 6.1) | ||
rubocop (>= 1.59.0) | ||
rubocop-capybara (>= 2.0.0) | ||
rubocop-factory_bot (>= 2.0.0) | ||
rubocop-rails (>= 2.25.0) | ||
rubocop-rspec (>= 3.0.1) | ||
rubocop-rspec_rails (>= 2.30.0) | ||
rubocop-factory_bot (2.26.1) | ||
rubocop (~> 1.61) | ||
rubocop-rails (2.25.1) | ||
activesupport (>= 4.2.0) | ||
rack (>= 1.1) | ||
rubocop (>= 1.33.0, < 2.0) | ||
rubocop-ast (>= 1.31.1, < 2.0) | ||
rubocop-rspec (3.0.1) | ||
rubocop (~> 1.61) | ||
rubocop-rspec_rails (2.30.0) | ||
rubocop (~> 1.61) | ||
rubocop-rspec (~> 3, >= 3.0.1) | ||
ruby-progressbar (1.13.0) | ||
stringio (3.1.1) | ||
strscan (3.1.0) | ||
syntax_tree (6.2.0) | ||
prettier_print (>= 1.2.0) | ||
syntax_tree-disable_ternary (1.0.0) | ||
thor (1.3.1) | ||
timeout (0.4.1) | ||
tzinfo (2.0.6) | ||
concurrent-ruby (~> 1.0) | ||
unicode-display_width (2.5.0) | ||
webrick (1.8.1) | ||
zeitwerk (2.6.16) | ||
|
||
PLATFORMS | ||
aarch64-linux | ||
arm-linux | ||
arm64-darwin | ||
x86-linux | ||
x86_64-darwin | ||
x86_64-linux | ||
|
||
DEPENDENCIES | ||
byebug | ||
pg (~> 1.2) | ||
rack | ||
rails_failover! | ||
rake (~> 12.0) | ||
redis (~> 4.1) | ||
rspec (~> 3.0) | ||
rubocop-discourse | ||
syntax_tree | ||
syntax_tree-disable_ternary | ||
|
||
BUNDLED WITH | ||
2.5.11 |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
module RailsFailover | ||
VERSION = "2.1.0" | ||
VERSION = "2.1.1" | ||
end |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# frozen_string_literal: true | ||
|
||
module GenericHelper | ||
def wait_for(timeout:, &blk) | ||
till = Time.now + (timeout.to_f / 1000) | ||
sleep 0.001 while Time.now < till && !blk.call | ||
end | ||
end |
Oops, something went wrong.