# Connection\_pool with\_connection strange behaviour - ActiveRecord 2.3.8

**URL:** <https://www.ruby-forum.com/t/connection-pool-with-connection-strange-behaviour-activerecord-2-3-8/192402>\
**Category:** Rails\
**Created:** [July 29, 2010, 4:34pm UTC](https://www.ruby-forum.com/t/connection-pool-with-connection-strange-behaviour-activerecord-2-3-8/192402 "2010-07-29T16:34:55Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![pyr0](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/da6949/32.png) [@pyr0](https://www.ruby-forum.com/u/pyr0)\
**Post date:** [July 29, 2010, 4:34pm UTC](https://www.ruby-forum.com/t/connection-pool-with-connection-strange-behaviour-activerecord-2-3-8/192402/1 "2010-07-29T16:34:55Z")

</div>

I noticed some strange behaviour with connection\_pool.with\_connection  
and it’s probably because I am not understanding the proper usage. If  
I call with\_connection, it seems to me that the connection within the  
block is not used with the ActiveRecord methods. First a simple ==  
comparison.

jruby-1.5.1 \> ActiveRecord::Base.connection\_pool.with\_connection{|c|  
ActiveRecord::Base.connection==c }  
=\> false

Then examining the number of active connections after using the  
with\_connection method:

=\>  
{“ActiveRecord  
::Base”=\>#ActiveRecord::ConnectionAdapters::ConnectionPool:0x105b3e5d}  
jruby-1.5.1 \>  
ActiveRecord::Base.connection\_pool.instance\_eval{ @checked\_out.length }  
=\> 0  
jruby-1.5.1 \> ActiveRecord::Base.connection\_pool.with\_connection{ |c|  
EmailAccount.last }  
jruby-1.5.1 \>  
ActiveRecord::Base.connection\_pool.instance\_eval{ @checked\_out.length }  
=\> 1

I found this lighthouse ticket  
[https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/1752](https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/1752)  
, but it seems to have been resolved. I am using ActiveRecord 2.3.8.

thx.

-karl
