鉴于它db是类型*sql.DB(uginglib/pq驱动程序),以下代码会导致连接泄漏:
rows, err := db.Query(
"select 1 from things where id = $1",
thing,
)
if err != nil {
return nil, fmt.Errorf("can't select thing (%d): %w", thing, err)
}
found := false
for rows.Next() {
found = true
break
}
反复调用此代码会增加打开连接的数量,直到用尽:
select sum(numbackends) from pg_stat_database;
// 5
// 6
// 7
// ...
// 80
我如何解决它?
Cats萌萌
相关分类