【问题标题】:knex broken after upgrading from Node.js v12 to Node.js v16.4.0从 Node.js v12 升级到 Node.js v16.4.0 后 knex 损坏
【发布时间】:2022-02-21 19:00:53
【问题描述】:

升级到 Node.js v16.4.0(从 Node.js v12)后,我遇到了以下错误。

我正在使用 knex 连接到 db (postgres) 并使用 ORM - objection.js

KnexTimeoutError: Knex: Timeout acquiring a connection. The pool is probably full. Are you missing a .transacting(trx) call?

请帮忙解决!

import Knex from "knex";

const getConnection = () => {
    try {
        return Knex({
            client: 'pg',
            connection: {
                user: 'user',
                password: 'password',
                host: 'dbhost',
                port: 5432,
                database: 'dbname',
            },
            pool: {
                min: 0,
                max: 10,
                idleTimeoutMillis: 10000,
                acquireTimeoutMillis: 30000,
            },
            acquireConnectionTimeout: 2000,
        });
    }
    catch (err) {
        throw err;
    }
}

const getTransaction = () => {
    const con = getConnection();
    const trx = con.transaction();
    return trx;    
}

【问题讨论】:

  • 没有足够的信息来说明它的来源。您创建的交易可能永远不会关闭。
  • 遇到同样的问题
  • 在普通的新项目上也有同样的问题,只有一个示例查询(见下文)。尝试了几种解决方法,包括连接限制设置为 -1 或 100 的池配置和 pg 设置。db .raw('select 1') .then(() => { console.log('Connected to database - OK') }) .catch(err => { console.error('Failed to connect to database with ${connection}: ${err}') process.exit(1) }) 使用 Node14(也尝试过 16、17)、Knex 0.95.13、PG 8.7.1

标签: javascript node.js postgresql node-modules knex.js


【解决方案1】:

遇到同样的问题,我将问题追溯到旧版本的“pg”包。

在做

npm i pg@latest

修好了

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-14
    • 2016-09-14
    • 2012-11-28
    • 1970-01-01
    • 2016-01-20
    • 1970-01-01
    相关资源
    最近更新 更多