Skip to content

Commit 47b5f86

Browse files
committed
Fix Rails 7.1 issue where ApplicationRecord.connection.active? returns false
1 parent 0954f55 commit 47b5f86

File tree

3 files changed

+53
-31
lines changed

3 files changed

+53
-31
lines changed

Gemfile.lock

Lines changed: 47 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ PATH
44
metasploit-framework (6.4.57)
55
aarch64
66
abbrev
7-
actionpack (~> 7.0.0)
8-
activerecord (~> 7.0.0)
9-
activesupport (~> 7.0.0)
7+
actionpack (~> 7.1.0)
8+
activerecord (~> 7.1.0)
9+
activesupport (~> 7.1.0)
1010
aws-sdk-ec2
1111
aws-sdk-ec2instanceconnect
1212
aws-sdk-iam
@@ -46,7 +46,7 @@ PATH
4646
metasploit-credential
4747
metasploit-model
4848
metasploit-payloads (= 2.0.189)
49-
metasploit_data_models
49+
metasploit_data_models (>= 6.0.7)
5050
metasploit_payloads-mettle (= 1.0.35)
5151
mqtt
5252
msgpack (~> 1.6.0)
@@ -123,28 +123,40 @@ GEM
123123
aarch64 (2.1.0)
124124
racc (~> 1.6)
125125
abbrev (0.1.2)
126-
actionpack (7.0.8.7)
127-
actionview (= 7.0.8.7)
128-
activesupport (= 7.0.8.7)
129-
rack (~> 2.0, >= 2.2.4)
126+
actionpack (7.1.5.1)
127+
actionview (= 7.1.5.1)
128+
activesupport (= 7.1.5.1)
129+
nokogiri (>= 1.8.5)
130+
racc
131+
rack (>= 2.2.4)
132+
rack-session (>= 1.0.1)
130133
rack-test (>= 0.6.3)
131-
rails-dom-testing (~> 2.0)
132-
rails-html-sanitizer (~> 1.0, >= 1.2.0)
133-
actionview (7.0.8.7)
134-
activesupport (= 7.0.8.7)
134+
rails-dom-testing (~> 2.2)
135+
rails-html-sanitizer (~> 1.6)
136+
actionview (7.1.5.1)
137+
activesupport (= 7.1.5.1)
135138
builder (~> 3.1)
136-
erubi (~> 1.4)
137-
rails-dom-testing (~> 2.0)
138-
rails-html-sanitizer (~> 1.1, >= 1.2.0)
139-
activemodel (7.0.8.7)
140-
activesupport (= 7.0.8.7)
141-
activerecord (7.0.8.7)
142-
activemodel (= 7.0.8.7)
143-
activesupport (= 7.0.8.7)
144-
activesupport (7.0.8.7)
139+
erubi (~> 1.11)
140+
rails-dom-testing (~> 2.2)
141+
rails-html-sanitizer (~> 1.6)
142+
activemodel (7.1.5.1)
143+
activesupport (= 7.1.5.1)
144+
activerecord (7.1.5.1)
145+
activemodel (= 7.1.5.1)
146+
activesupport (= 7.1.5.1)
147+
timeout (>= 0.4.0)
148+
activesupport (7.1.5.1)
149+
base64
150+
benchmark (>= 0.3)
151+
bigdecimal
145152
concurrent-ruby (~> 1.0, >= 1.0.2)
153+
connection_pool (>= 2.2.5)
154+
drb
146155
i18n (>= 1.6, < 2)
156+
logger (>= 1.4.2)
147157
minitest (>= 5.1)
158+
mutex_m
159+
securerandom (>= 0.3)
148160
tzinfo (~> 2.0)
149161
addressable (2.8.7)
150162
public_suffix (>= 2.0.2, < 7.0)
@@ -202,6 +214,7 @@ GEM
202214
chunky_png (1.4.0)
203215
coderay (1.1.3)
204216
concurrent-ruby (1.3.4)
217+
connection_pool (2.5.0)
205218
cookiejar (0.3.4)
206219
crass (1.0.6)
207220
csv (3.3.2)
@@ -391,22 +404,28 @@ GEM
391404
rack-protection (3.2.0)
392405
base64 (>= 0.1.0)
393406
rack (~> 2.2, >= 2.2.4)
407+
rack-session (1.0.2)
408+
rack (< 3)
394409
rack-test (2.2.0)
395410
rack (>= 1.3)
411+
rackup (1.0.1)
412+
rack (< 3)
413+
webrick
396414
rails-dom-testing (2.2.0)
397415
activesupport (>= 5.0.0)
398416
minitest
399417
nokogiri (>= 1.6)
400418
rails-html-sanitizer (1.6.2)
401419
loofah (~> 2.21)
402420
nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0)
403-
railties (7.0.8.7)
404-
actionpack (= 7.0.8.7)
405-
activesupport (= 7.0.8.7)
406-
method_source
421+
railties (7.1.5.1)
422+
actionpack (= 7.1.5.1)
423+
activesupport (= 7.1.5.1)
424+
irb
425+
rackup (>= 1.0.0)
407426
rake (>= 12.2)
408-
thor (~> 1.0)
409-
zeitwerk (~> 2.5)
427+
thor (~> 1.0, >= 1.2.2)
428+
zeitwerk (~> 2.6)
410429
rainbow (3.1.1)
411430
rake (13.2.1)
412431
rasn1 (0.14.0)
@@ -527,6 +546,7 @@ GEM
527546
sawyer (0.9.2)
528547
addressable (>= 2.3.5)
529548
faraday (>= 0.17.3, < 3)
549+
securerandom (0.4.1)
530550
simplecov (0.18.2)
531551
docile (~> 1.1)
532552
simplecov-html (~> 0.11)

db/schema.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#
1111
# It's strongly recommended that you check this file into your version control system.
1212

13-
ActiveRecord::Schema[7.0].define(version: 2025_02_04_172657) do
13+
ActiveRecord::Schema[7.1].define(version: 2025_02_04_172657) do
1414
# These are extensions that must be enabled in order to support this database
1515
enable_extension "plpgsql"
1616

lib/msf/core/db_manager/connection.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,11 @@ def create_db(opts)
116116
def connection_established?
117117
begin
118118
# use with_connection so the connection doesn't stay pinned to the thread.
119-
ApplicationRecord.connection_pool.with_connection {
120-
ApplicationRecord.connection.active?
121-
}
119+
ApplicationRecord.connection_pool.with_connection do
120+
# There's a bug in Rails 7.1 where ApplicationRecord.connection.active? returns false even though we can get a connection
121+
# calling `verify!` instead will ensure we are connected even if `active?` incorrectly returns false
122+
ApplicationRecord.connection.verify!
123+
end
122124
rescue ActiveRecord::ConnectionNotEstablished, PG::ConnectionBad => error
123125
false
124126
end

0 commit comments

Comments
 (0)