【问题标题】:Node ECONNRESET tunnel-ssh and mongoose节点 ECONNRESET 隧道-ssh 和猫鼬
【发布时间】:2020-05-02 00:38:15
【问题描述】:

当我启动 Express 时,它会在大约 5 分钟后崩溃。

使用此依赖项。

  • 快递4.17.1
  • 猫鼬 5.9.7
  • 隧道-ssh 4.1.4

等待大约 5 分钟后,出现这样的错误。

[nodemon] starting `node bin/www`
events.js:187
      throw er; // Unhandled 'error' event
      ^

Error: read ECONNRESET
    at TCP.onStreamRead (internal/stream_base_commons.js:201:27)
Emitted 'error' event on Server instance at:
    at Client.emit (events.js:210:5)
    at Socket.<anonymous> (/Users/project/node_modules/tunnel-ssh/node_modules/ssh2/lib/client.js:294:10)
    at Socket.emit (events.js:210:5)
    at emitErrorNT (internal/streams/destroy.js:92:8)
    at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)
    at processTicksAndRejections (internal/process/task_queues.js:80:21) {
  errno: 'ECONNRESET',
  code: 'ECONNRESET',
  syscall: 'read',
  level: 'client-socket'
}
[nodemon] app crashed - waiting for file changes before starting...

数据库连接。

module.exports.A = async () => {
  this.ssh = await tunnel({
    keepAlive: true,
    host: HOST,
    username: USERNAME,
    privateKey: fs.readFileSync(KEY),
    dstHost: DST_Host,
    dstPort: DST_Port
  })

  mongoose.connect(URL, {
    useNewUrlParser: true,
    useUnifiedTopology: true,
    useCreateIndex: true
  })
}

module.exports.B = async () => {
  this.ssh.close()
}

SSH 配置。

Host *
  ClientAliveInterval 8
  ServerAliveInterval 60
  TCPKeepAlive yes

【问题讨论】:

  • 问题是什么?当没有任何东西通过它们传输时,ssh 隧道经常会中断。请使用设置 ssh 隧道的代码扩展您的问题。另请查看选项 "keepAlive:true" 。同样在服务器端,您可以调整 /etc/ssh/sshd_config 以启用 heartbeats

标签: node.js mongodb express mongoose ssh


【解决方案1】:

已解决

  mongoose.connect(URL, {
    useNewUrlParser: true,
    useUnifiedTopology: true,
    useCreateIndex: true,
    serverSelectionTimeoutMS: 30000, // Use this.
    socketTimeoutMS: 30000 // Use this.
  })

【讨论】:

    猜你喜欢
    • 2016-07-02
    • 2020-07-31
    • 1970-01-01
    • 1970-01-01
    • 2013-08-12
    • 2023-03-17
    • 2018-10-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多