node-protgresを使用してnodejsアプリケーションのdbを操作します。node-postgres:[エラー]このソケットは相手側で終了しました
は、私がやっていること:
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
});
});
}
機能が正常に動作している、しかし、サーバーは私に深刻にOKエラーレポートを送信し続けます。私はログを確認しました:
idle client error This socket has been ended by the other party Error: This socket has been ended by the other party at Socket.writeAfterFIN [as write] (net.js:291:12) at Connection.end (/var/app/current/node_modules/pg/lib/connection.js:313:22) at global.Promise (/var/app/current/node_modules/pg/lib/client.js:410:23) at Client.end (/var/app/current/node_modules/pg/lib/client.js:409:12) at Pool._remove (/var/app/current/node_modules/pg-pool/index.js:135:12) at Timeout.setTimeout (/var/app/current/node_modules/pg-pool/index.js:38:12) at ontimeout (timers.js:365:14) at tryOnTimeout (timers.js:237:5) at Timer.listOnTimeout (timers.js:207:5)
問題は 'done()'が動作しないか、間違った場所に置かれたと考えられます。
ご迷惑をおかけして申し訳ございません。
こんにちは、記事を共有していただきありがとうございます。このチュートリアルではプールを使用せず、node-postgresの代わりにpg-promiseを使用します。あなたは私にどのような使用を提案していますか?ところで、それは役に立つ記事です –