From 51b8cb2b7fc1a3f696a33116afd36c35dbc8c8fc Mon Sep 17 00:00:00 2001 From: Jeremy Evans Date: Fri, 28 Jun 2024 09:01:20 -0700 Subject: [PATCH] Add nocov markings in threaded connection pools This surround code that's only possible to hit in a race condition, and possibly only on JRuby. --- lib/sequel/connection_pool/sharded_threaded.rb | 4 ++++ lib/sequel/connection_pool/threaded.rb | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/lib/sequel/connection_pool/sharded_threaded.rb b/lib/sequel/connection_pool/sharded_threaded.rb index 0afa2a52c..79bd3d96f 100644 --- a/lib/sequel/connection_pool/sharded_threaded.rb +++ b/lib/sequel/connection_pool/sharded_threaded.rb @@ -221,9 +221,13 @@ def acquire(thread, server) def acquire_available(thread, server, timeout) sync do # Check if connection was checked in between when assign_connection failed and now. + # This is very unlikely, but necessary to prevent a situation where the waiter + # will wait for a connection even though one has already been checked in. + # :nocov: if conn = next_available(server) return(allocated(server)[thread] = conn) end + # :nocov: @waiters[server].wait(@mutex, timeout) diff --git a/lib/sequel/connection_pool/threaded.rb b/lib/sequel/connection_pool/threaded.rb index 0c61319bc..de4980762 100644 --- a/lib/sequel/connection_pool/threaded.rb +++ b/lib/sequel/connection_pool/threaded.rb @@ -167,9 +167,13 @@ def acquire(thread) def acquire_available(thread, timeout) sync do # Check if connection was checked in between when assign_connection failed and now. + # This is very unlikely, but necessary to prevent a situation where the waiter + # will wait for a connection even though one has already been checked in. + # :nocov: if conn = next_available return(@allocated[thread] = conn) end + # :nocov: @waiter.wait(@mutex, timeout)