@mysql/xdevapi ECONNREFUSED 不释放连接
@mysql/xdevapi ECONNREFUSED doesn't release connection
我在本地安装 mysql-8.0.15-winx64.
使用 @mysql/xdevapi npm 包(版本 8.0.22)
我已将池设置为启用并尝试从客户端检索会话。如果我在 mysql 准备就绪之前执行此操作,那么我会收到预期的 ECONNREFUSED 异常,但连接似乎永远不会被释放。如果池大小为 1,则所有后续尝试 getSession
异常是从 getSession 方法中抛出的,因此没有返回会话供我手动调用 .end()
。
const mysqlx = require('@mysql/xdevapi');
const client = mysqlx.getClient(config, { pooling: { enabled: true, maxSize: 1, queueTimeout: 2000 } });
const session = await this.client.getSession(); // returns ECONNREFUSED exception
/*
wait for mysql to be ready and accepting connections
*/
const session = await this.client.getSession(); // returns connection pool queue timeout exception because the previous session hasn't been returned to the pool
如何确保中止的连接返回到池中?
这是一个错误,我鼓励您使用 Connector for Node.js
类别在 https://bugs.mysql.com/ 上报告它。
想到的唯一解决方法是,如果 getSession()
方法 returns 被拒绝 Promise
(有或没有特定错误),则重新创建池。例如,类似于:
const poolConfig = { pooling: { enabled: true, maxSize: 1, queueTimeout: 2000 } }
let pool = mysqlx.getClient(config, poolConfig)
let session = null
try {
session = await pool.getSession()
} catch (err) {
await pool.close()
pool = mysqlx.getClient(config, poolConfig)
session = await pool.getSession()
// do something
}
这是一个丑陋的解决方案,可能很难硬塞进您的设计中,但至少,它可以让您享受连接池的其他好处。
免责声明:我是 MySQL X DevAPI Connector for Node.js
的首席开发人员
我在本地安装 mysql-8.0.15-winx64.
使用 @mysql/xdevapi npm 包(版本 8.0.22)我已将池设置为启用并尝试从客户端检索会话。如果我在 mysql 准备就绪之前执行此操作,那么我会收到预期的 ECONNREFUSED 异常,但连接似乎永远不会被释放。如果池大小为 1,则所有后续尝试 getSession
异常是从 getSession 方法中抛出的,因此没有返回会话供我手动调用 .end()
。
const mysqlx = require('@mysql/xdevapi');
const client = mysqlx.getClient(config, { pooling: { enabled: true, maxSize: 1, queueTimeout: 2000 } });
const session = await this.client.getSession(); // returns ECONNREFUSED exception
/*
wait for mysql to be ready and accepting connections
*/
const session = await this.client.getSession(); // returns connection pool queue timeout exception because the previous session hasn't been returned to the pool
如何确保中止的连接返回到池中?
这是一个错误,我鼓励您使用 Connector for Node.js
类别在 https://bugs.mysql.com/ 上报告它。
想到的唯一解决方法是,如果 getSession()
方法 returns 被拒绝 Promise
(有或没有特定错误),则重新创建池。例如,类似于:
const poolConfig = { pooling: { enabled: true, maxSize: 1, queueTimeout: 2000 } }
let pool = mysqlx.getClient(config, poolConfig)
let session = null
try {
session = await pool.getSession()
} catch (err) {
await pool.close()
pool = mysqlx.getClient(config, poolConfig)
session = await pool.getSession()
// do something
}
这是一个丑陋的解决方案,可能很难硬塞进您的设计中,但至少,它可以让您享受连接池的其他好处。
免责声明:我是 MySQL X DevAPI Connector for Node.js
的首席开发人员