     getName: ->
         @_factory.name
     acquire: (callback, opts = {})->
-        @semTake
+        self = @
+        self.semTake
             priority: opts.priority
             num: 1
             timeOut: opts.timeOut
             onTimeOut: opts.onTimeOut
-            onTake: =>
-                if @_avalaible.length is 0
-                    @_factory.create (err, client)=>
+            onTake: ->
+                logger.debug "[#{self._factory.name}] [#{self.id}] acquire", self._avalaible.length
+                if self._avalaible.length is 0
+                    self._factory.create (err, client)->
                         return callback err if err
-                        @_created.push client
-                        @_removeIdle @_created.length - 1, client
+                        self._created.push client
+                        self._removeIdle client
                         callback null, client
                         return
                     return
-                client = @_avalaible.shift()
-                @_removeIdle @_created.indexOf(client), client
+                client = self._avalaible.shift()
+                self._removeIdle client
                 callback null, client
                 return
     release: (client)->
         index = @_created.indexOf client
         if ~index
+            logger.debug "[#{this._factory.name}] [#{this.id}] release '#{client.id}'. Avalaible #{this._avalaible.length}"
             @_avalaible.push client
-            @_idle index, client
+            @_idle client
             return @semGive()
         return false
-    _idle: (index, client)->
+    _idle: (client)->
+        self = @
         if @_factory.idle > 0
-            return if @_factory.min is @_created.length
-            @_timers[index] = setTimeout =>
-                return if @_factory.min is @_created.length
-                @destroy client
-                return
-            , @_factory.idle
-        return
-    _removeIdle: (index, client)->
-        clearTimeout @_timers[index]
-        return
-    destroy: (client)->
+            self._removeIdle client
+            self._timers[client.id] = setTimeout ->
+                self.destroy client
+                return
+            , self._factory.idle
+        return
+    _removeIdle: (client)->
+        clearTimeout @_timers[client.id]
+        delete @_timers[client.id]
+        return
+    destroy: (client, force)->
         index = @_created.indexOf client
+
+        # ensure minimum
         if ~index
-            @_created.splice index, 1
-            @_factory.destroy client
-            @_ensureMinimum()
-            return true
+            if force or @_factory.min < @_created.length
+                logger.debug "[#{this._factory.name}] [#{this.id}] destroying '#{client.id}'. #{this._avalaible.length}/#{this._created.length}"
+                @_created.splice index, 1
+
+                # remove it from available since it will be destroyed
+                index = @_avalaible.indexOf client
+                @_avalaible.splice index, 1 if ~index
+
+                @_factory.destroy client
+                logger.debug "[#{this._factory.name}] [#{this.id}] destroyed '#{client.id}'. #{this._avalaible.length}/#{this._created.length}"
+
+                @_ensureMinimum() if force
+                return true
+            else
+                @_idle client
         return false
     _superDestroy: (safe, _onDestroy)->
         SemaphorePool.__super__.destroy.call @, safe, _onDestroy
 
     destroyAll: (safe, _onDestroy)->
+        self = @
         if safe isnt false
-            @_superDestroy true, =>
-                @_onDestroy()
+            self._superDestroy true, ->
+                self._onDestroy()
                 _onDestroy() if 'function' is typeof _onDestroy
                 return
         else
-            @_superDestroy false, =>
-                @_onDestroy()
+            self._superDestroy false, ->
+                self._onDestroy()
                 _onDestroy() if 'function' is typeof _onDestroy
                 return
         return


        @adapter = internal.getAdapter @options

        super
            name: @options.name

            create: (callback)=>
                logger.debug "#{@_factory.name} create", @id
                @adapter.createConnection @options, (err, client)=>
                    return callback(err, null) if err

                    client.on 'error', (err)=>
                        # @destroy client
                        @emit 'error', err
                        return

                    # Remove connection from pool on disconnect
                    client.on 'end', (err)=>
                        return if client._destroying
                        @destroy client
                        return

                    callback null, client

                    return
                return

            destroy: (client)->
                return if client._destroying
                logger.debug "[#{self._factory.name}] [#{self.id}] destroy"
                client._destroying = true
                client.end()
                return

            max: self.options.maxConnection
            min: self.options.minConnection
            idle: self.options.idleTimeout * 1000

        self.check(next) if typeof next is 'function'
        return

    check: (next)->
