首页 文章

node-postgres:[错误]此套接字已被另一方结束

提问于
浏览
0

我使用node-protgres来操作我的nodejs应用程序中的数据库 .

我做了什么:

const { Pool, Client } = require('pg')
var dbconnect = {
    user: 'xxxxx',
    database: 'xxxxx',
    password: 'xxxxx', 
    host: 'xxxxx.yyyyy.zzzzz.eu-west-1.rds.amazonaws.com',
    port: 0000, 
    max: 20, // max number of clients in the pool
    idleTimeoutMillis: 30000,
    connectionTimeoutMillis: 2000 
};
const pool = new Pool(dbconnect);
pool.on('error', function (err, client) {
    console.error('idle client error', err.message, err.stack)
});

function listOfPets(req, res) {

 pool.connect(function (err, client, done) {
        if (err) {
            return console.error('error fetching client from pool', err);
        }

        var sql =
            "SELECT * FROM pets"
        client.query(sql, function (err, result) {

                done();

                if (err) {
                    return console.error('error running query', err);
                }

                ... //Handle the result 

            });
    });

}

该功能工作正常,但服务器继续向我发送错误报告确定为严重 . 我检查了日志:

idle client error此套接字已被另一方结束错误:此套接字已由另一方在Connection.end(/ var / app)上的Socket.writeAfterFIN [as write](net.js:291:12)结束/current/node_modules/pg/lib/connection.js:313:22)在Client.end(/ var)的global.Promise(/var/app/current/node_modules/pg/lib/client.js:410:23) /app/current/node_modules/pg/lib/client.js:409:12)在Timeout.setTimeout上的Pool._remove(/var/app/current/node_modules/pg-pool/index.js:135:12) /var/app/current/node_modules/pg-pool/index.js:38:12)attimeout(timers.js:365:14)在tryOnTimeout(timers.js:237:5)的Timer.listOnTimeout(计时器 . ) JS:207:5)

我认为问题来自于'done()'不起作用或放在错误的地方 .

任何建议表示赞赏 .

1 回答

相关问题