Skip to content

Commit

Permalink
Add nocov markings in threaded connection pools
Browse files Browse the repository at this point in the history
This surround code that's only possible to hit in a
race condition, and possibly only on JRuby.
  • Loading branch information
jeremyevans committed Jun 28, 2024
1 parent e55fe96 commit 51b8cb2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/sequel/connection_pool/sharded_threaded.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 4 additions & 0 deletions lib/sequel/connection_pool/threaded.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 51b8cb2

Please sign in to comment.