【问题标题】:node.js ECONNRESET error after a while idle一段时间空闲后node.js ECONNRESET错误
【发布时间】:2018-03-28 07:45:44
【问题描述】:

我使用 node.js 和 PostgreSQL 作为我的数据库。我使用下面的代码来连接我的数据库。

 const pool = new pg.Pool(config);
pool.connect((err) => {
  if (err) {
    console.log(err);
    return;
  }
  console.log('connected to database', config.database);
});

这是配置代码:

const crypto = require('crypto').randomBytes(256).toString('hex');
module.exports = {
    host:'192.168.87.8',
    user: 'fjavadpour',
    database: 'fj_correspondence',
    password: 'Fariba321',
    port: 5432,
    max: 200,
    secret:crypto,
    idleTimeoutMillis: 72000000
};

但是我的数据库连接会在空闲大约一小时后崩溃并停止。 我该如何解决?

【问题讨论】:

  • 您的主机在哪里?是否在同一个网络内?
  • @AnshulVerma 是的!我一开始可以连接到主机,但是大约一个小时后我没有联系数据库时它崩溃并出现 ECONNRESET 错误

标签: node.js postgresql server timeout


【解决方案1】:

您可以尝试将keepAlive:true 添加到您的配置中然后检查吗?

【讨论】:

    猜你喜欢
    • 2014-05-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-22
    • 1970-01-01
    • 2014-01-24
    相关资源
    最近更新 更多