Bugfix: don't try to cull connections from an empty pool.
The first step in culling connections was to take a subset of the pool's connections from index 0 to numToCull. This leads to an error if numToCull is also zero.
This commit is contained in:
parent
9625ac6a5e
commit
1d7c955805
@ -1,6 +1,6 @@
|
|||||||
# Package
|
# Package
|
||||||
|
|
||||||
version = "1.0.1"
|
version = "1.0.2"
|
||||||
author = "Jonathan Bernard"
|
author = "Jonathan Bernard"
|
||||||
description = "Lightweight Postgres ORM for Nim."
|
description = "Lightweight Postgres ORM for Nim."
|
||||||
license = "GPL-3.0"
|
license = "GPL-3.0"
|
||||||
|
@ -62,6 +62,8 @@ proc maintain(pool: DbConnPool): void =
|
|||||||
let freeConns = pool.conns.filterIt(it.free)
|
let freeConns = pool.conns.filterIt(it.free)
|
||||||
if pool.conns.len > pool.cfg.poolSize and freeConns.len > 0:
|
if pool.conns.len > pool.cfg.poolSize and freeConns.len > 0:
|
||||||
let numToCull = min(freeConns.len, pool.conns.len - pool.cfg.poolSize)
|
let numToCull = min(freeConns.len, pool.conns.len - pool.cfg.poolSize)
|
||||||
|
|
||||||
|
if numToCull > 0:
|
||||||
let toCull = freeConns[0..numToCull]
|
let toCull = freeConns[0..numToCull]
|
||||||
pool.conns.keepIf((pc) => toCull.allIt(it.id != pc.id))
|
pool.conns.keepIf((pc) => toCull.allIt(it.id != pc.id))
|
||||||
for culled in toCull:
|
for culled in toCull:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user