Skip to content

Commit 3caf120

Browse files
committed
Make connection_validator and connection_expiration extensions correct handle shared_timed_queue connection pool (Fixes #2354)
Previously, these extensions did not handle the shared_timed_queue connection pool when disconnecting connections. The sharded_timed_queue needs extra care due to it's management of the pool size. Add a disconnect_acquired_connection private method to the connection pool designed for use by these extensions, and call that. Override the method in shared_timed_queue to correctly decrement the size.
1 parent cb8d60d commit 3caf120

File tree

7 files changed

+18
-2
lines changed

7 files changed

+18
-2
lines changed

CHANGELOG

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
=== master
22

3+
* Make connection_validator and connection_expiration extensions correct handle shared_timed_queue connection pool (jeremyevans) (#2354)
4+
35
* Add connection_checkout_event_callback extension to assist in collecting telemetry information (jeremyevans)
46

57
=== 5.101.0 (2026-02-01)

lib/sequel/connection_pool.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,12 @@ def disconnect_connection(conn)
131131
db.disconnect_connection(conn)
132132
end
133133

134+
# Only for use by extension that need to disconnect a connection inside acquire.
135+
# Takes the connection and any arguments accepted by acquire.
136+
def disconnect_acquired_connection(conn, *)
137+
disconnect_connection(conn)
138+
end
139+
134140
# Whether the given exception is a disconnect exception.
135141
def disconnect_error?(exception)
136142
exception.is_a?(Sequel::DatabaseDisconnectError) || db.send(:disconnect_error?, exception, OPTS)

lib/sequel/connection_pool/sharded_timed_queue.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,12 @@ def disconnect_connections(conns)
225225
conns.each{|conn| disconnect_connection(conn)}
226226
end
227227

228+
# Only for use by extension that need to disconnect a connection inside acquire.
229+
# Takes the connection and any arguments accepted by acquire.
230+
def disconnect_acquired_connection(conn, _, server)
231+
disconnect_pool_connection(conn, server)
232+
end
233+
228234
# Decrement the current size of the pool for the server when disconnecting connections.
229235
#
230236
# Calling code should not have the mutex when calling this.

lib/sequel/extensions/connection_expiration.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def acquire(*a)
9191
sync{@allocated.delete(Sequel.current)}
9292
end
9393

94-
disconnect_connection(conn)
94+
disconnect_acquired_connection(conn, *a)
9595
redo
9696
end
9797
end

lib/sequel/extensions/connection_validator.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def acquire(*a)
118118
sync{@allocated.delete(Sequel.current)}
119119
end
120120

121-
disconnect_connection(conn)
121+
disconnect_acquired_connection(conn, *a)
122122
redo if valid == false
123123
end
124124
end

spec/extensions/connection_expiration_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ def disconnect_connection(conn)
4747
c2 = @db.synchronize{|c| c}
4848
@db.sqls.must_equal ['disconnect']
4949
c2.wont_be_same_as(c1)
50+
@db.pool.size.must_equal 1
5051
end
5152

5253
it "should disconnect only expired connections among multiple" do

spec/extensions/connection_validator_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ def connect(server)
5353
c2 = @db.synchronize{|c| c}
5454
@db.sqls.must_equal ['SELECT NULL', 'disconnect']
5555
c2.wont_be_same_as(c1)
56+
@db.pool.size.must_equal 1
5657
end
5758

5859
it "should assume that exceptions raised during valid_connection mean the connection is not valid" do

0 commit comments

Comments
 (0)