[BUG] No new connections being made on empty pool when maxSize is less than incrementSize
还没有人认领这个 Issue。
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 52/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 停滞
- 技术栈
- javascript, node.js
调研方向
从 lib/Pool.js 第 211-212 行附近开始,使用 maxSize: 5、initialSize: 1 和默认的 incrementSize 重现空池的情况。当 maxSize 小于 incrementSize 时,验证 pool 在 nativeClose 和 poolSize 减少后能够创建替换连接。
由索引模型根据 Issue 内容生成。
描述
Describe your system
odbcPackage Version: 2.4.8- ODBC Driver: Progress OpenEdge ODBC Driver 8.0.0
- Database Name: OpenEdge
- Database Version: 11.7
- Database OS: Windows
- Node.js Version: 18.20.2
- Node.js OS: linux/amd64
Describe the bug
This bug is related to pooling.
On an initialized empty pool (with no active connections), if the incrementSize is larger than the maxSize, if no new connections are being created, no new connections can be created.
For example:
If there is only one connection in a pool and that single connection dies (i.e. the socket gets closed), the connection needs to be closed manually with nativeClose and poolSize needs to be decremented manually. We need to call nativeClose instead of close because close will just release that dead connection back into the pool without closing it.
In this state, no new connection can be made.
I discovered this with a pool maxSize of 5, initialSize of 1 and without defining the incrementSize (it defaults to 10).
Expected behavior
A new connection should be made on an empty pool regardless of the maxSize and incrementSize settings on the pool.
To Reproduce
- Connect to database using a pool with options
{ maxSize: 5, initialSize: 1, reuseConnections: true } - Force close the connection socket from on the database server
- Call nativeClose on the connection in the pool and decrement the poolSize
- Call connect on the pool to obtain a new connection.
Code
const query = async (query) => {
let odbcConnection = await connect()
for (let tries = 0; tries < maxNumberOfTries; tries++) {
try {
const res = await odbcConnection.query(query)
await odbcConnection.close()
return res
} catch (error) {
if (
error.odbcErrors?.[0]?.message ===
"[DataDirect][ODBC Progress OpenEdge Wire Protocol driver]Socket closed."
) {
await odbcConnection.nativeClose()
this.pool.poolSize--
odbcConnection = await connect()
}
}
}
throw new Error("Failed to query the database")
}
- The offending code:
I believe the issue stems from this if statement in /lib/Pool.js on line 211 and 212
https://github.com/IBM/node-odbc/blob/c1cbc136670c50a55813b391637fd465ea0f3e81/lib/Pool.js#L211
The main issue here is that it doesn't make sense for incrementSize to be less than maxSize, but the default incrementSize is 10, so any maxSize less than that can cause issues.
Maybe the best way to handle this would be set the default incrementSize to min(maxSize, 10), or change the logic in the if condition to handle this case.
- 主要语言
- JavaScript
- 星标
- 159
- 派生
- 92
- 平均合并
- 5 小时 59 分钟
- 30 天内合并 PR
- 3
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
IBM/node-odbc 的其他 Issue
-
难度 1/5 1 小时以内 新手友好度 85/100
-
security
难度 3/5 1-2 天 新手友好度 45/100
-
难度 4/5 3-5 天 新手友好度 48/100
-
难度 4/5 3-5 天 新手友好度 35/100
-
难度 4/5 3-5 天 新手友好度 38/100
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 82/100
sallowayma-git/IELTS-practice#248 ·
维护者通常 1 天内回复
-
a11y data import fails with "missing --authors parameter" (npm drops flags in `bin/configure.js`)未关闭
难度 2/5 1-3 小时 新手友好度 90/100
-
难度 2/5 1-3 小时 新手友好度 74/100
Emanuele-web04/remodex#203 ·
维护者通常 1 天内回复
-
needs-human work-class: mechanical
难度 2/5 半天 新手友好度 84/100
melodic-software/claude-code-plugins#7994 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 68/100
keyxmakerx/Chronicle#1532 ·
维护者通常 1 天内回复