On Fri, Mar 07, 2025 at 05:07:44PM -0700, Soren Stoutner wrote:
I am trying to troubleshoot the following bug in ruby-with-advisory-lock.

https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1095888

The test is failing with because of a connection timeout.

ParallelismTest#test_doesn't_create_multiple_duplicate_rows_with_advisory_locks 
=
#<Thread:0x00007f0594867270 
/builds/ruby-team/ruby-with-advisory-lock/debian/output/
source_dir/test/parallelism_test.rb:13 run> terminated with exception
(report_on_exception is true):
/usr/share/rubygems-integration/all/gems/activerecord-7.2.2.1/lib/active_record/
connection_adapters/abstract/connection_pool/queue.rb:128:in `block in 
wait_poll': could
not obtain a connection from the pool within 5.000 seconds (waited 5.000 
seconds); all
pooled connections were in use (ActiveRecord::ConnectionTimeoutError)

https://salsa.debian.org/ruby-team/ruby-with-advisory-lock/-/jobs/7214292#L1668

The test succeeded on Rails 6.

Does anyone know off the top of their head what might have changed in Rails 7 
that
would cause this timeout?

The error message feels like some type of problem/incompatibility in the testing
environment as opposed to an actual problem ruby-with-advisory-lock would 
encounter
running on Rails 7 in the real world.  If that is the case, I can simply 
disable the test (at
least temporarily).  But I don’t want to do that if this is an actual problem 
that would
manifest in a production environment.

I searched the internet for "activerecord pool". The first hit was

https://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/ConnectionPool.html

In there I learned, in the "Options" section, that the `pool` database connection option controls how many connections are open in the connection pool, and it defaults to 5.

Looking at the code in test/parallelism_test.rb, I see that it creates 10 workers, who will content for the connections in the pool. Raising the number of connections in the pool makes the test pass for me:

----------------8<----------------8<----------------8<-----------------
diff --git i/test/test_helper.rb w/test/test_helper.rb
index 2a8c43f..7257b69 100644
--- i/test/test_helper.rb
+++ w/test/test_helper.rb
@@ -18,6 +18,7 @@ end
 ActiveRecord::Base.configurations = {
   default_env: {
     url: ENV.fetch('DATABASE_URL', 
"sqlite3://#{Dir.tmpdir}/#{SecureRandom.hex}.sqlite3"),
+    pool: 20,
     properties: { allowPublicKeyRetrieval: true } # for JRuby madness
   }
 }
----------------8<----------------8<----------------8<-----------------

Attachment: signature.asc
Description: PGP signature

Reply via email to