Permalink
Browse files

make sure connections returned after close are marked as in_use

  • Loading branch information...
1 parent da0595d commit 5f26ce699f9e695c434cbff20626a9ff4d3114e4 @tenderlove tenderlove committed Mar 12, 2012
@@ -269,11 +269,27 @@ def checkin(conn)
conn.expire
@queue.signal
end
+
+ release conn
end
end
private
+ def release(conn)
+ thread_id = nil
+
+ if @reserved_connections[current_connection_id] == conn
+ thread_id = current_connection_id
+ else
+ thread_id = @reserved_connections.keys.find { |k|
+ @reserved_connections[k] == conn
+ }
+ end
+
+ @reserved_connections.delete thread_id if thread_id
+ end
+
def new_connection
ActiveRecord::Base.send(spec.adapter_method, spec.config)
end
@@ -31,6 +31,16 @@ def active_connections(pool)
pool.connections.find_all(&:in_use?)
end
+ def test_checkout_after_close
+ connection = pool.connection
+ assert connection.in_use?
+
+ connection.close
+ assert !connection.in_use?
+
+ assert pool.connection.in_use?
+ end
+
def test_released_connection_moves_between_threads
thread_conn = nil

3 comments on commit 5f26ce6

@jrochkind

Awesome. Am hoping this helps solve a related problem I am trying to investigate in my app, causing it to require more connections in the pool than I think it ought to, since rails 3.0 even.

However, you now have two similar but different methods with similar but different names: release(conn) and release_connection(conn). Can you maybe put some inline comments in the new release explaining how it's different than release_connection

Alternately, do they need to be two different methods? The new release seems to possibly do a superset of what the old release_connection did -- should they just be combined?

@tenderlove
Member

release_connection actually takes the thread id associated with the connection. I think it's meant to be called with no arguments. release is meant to be called with a connection, and it's private. We could probably combine release_connection and release, but I wanted to make the smallest change possible. Fix bug in one commit, refactor later. :-)

@jrochkind
Please sign in to comment.