rails/rails — Issue #4276: The close method of middlewares (body class) is not getting called.
Author: jhllnd
Created: 2012-01-03 13:58:14+00:00
State: open

I noticed that the close method of the [identity map middleware body class] (https://github.com/rails/rails/blob/master/activerecord/lib/active_record/identity_map.rb#L127) is not getting called.

You can verify that with this monkey patch:

```ruby
module ActiveRecord
module IdentityMap
class Middleware
class Body
def initialize(target, original)
Rails.logger.info("initialized")

@target = target
@original = original
end

def each(&block)
@target.each(&block)
end

def close
Rails.logger.info("closed")

@target.close if @target.respond_to?(:close)
ensure
IdentityMap.enabled = @original
IdentityMap.clear
end
end
end
end
end
```

Don't forget to enable the identity map with:

```ruby
config.active_record.identity_map = true
```