Edited at

AWS, RDS(PostgreSQL), Lambda(Node.JS)の組み合わせで30秒ぐらいコネクションを使っていると落ちる

下記のようにしていると落ちる。

'use strict'

var DBDao = require("../utils/dao").DBDao;

class Dummy {
static async exec(i) {
console.log("----------------")
var sql = `select * from sometable;`

for (var i = 0; i < 1000000; i++) {
var dao = new DBDao();
console.log(i);
var results = await dao.query(sql, []);
// .then((res) => {
// return new Promise(function (resolve, reject) {
// // dao.close();
// resolve();
// });
// })
console.log(results.length);
dao.close();
}
}
}

module.exports.Dummy = Dummy;

下記のようなエラーで落ちる。

select * from itemtable; []

248
781
select * from itemtable; []
248
782
select * from itemtable; []
query error Connection terminated by user Error: Connection terminated by user
at Client.end (/Users/yousan/git/test/node_modules/pg/lib/client.js:402:36)
at Pool._remove (/Users/yousan/git/test/node_modules/pg-pool/index.js:135:12)
at Timeout.setTimeout (/Users/yousan/test/node_modules/pg-pool/index.js:38:12)
at ontimeout (timers.js:460:11)
at tryOnTimeout (timers.js:298:5)
at Timer.listOnTimeout (timers.js:261:5)
error: Error: Connection terminated by user
at Client.end (/Users/yousan/git/test/node_modules/pg/lib/client.js:402:36)
at Pool._remove (/Users/yousan/git/test/node_modules/pg-pool/index.js:135:12)
at Timeout.setTimeout (/Users/yousan/git/test/node_modules/pg-pool/index.js:38:12)
at ontimeout (timers.js:460:11)
at tryOnTimeout (timers.js:298:5)
at Timer.listOnTimeout (timers.js:261:5)

時間を測ると30秒ぐらいでおちている。

引き続き調査中…。