Issue
When I start Express, it crashes in about 5 minutes.
Use this dependencies.
- express 4.17.1
- mongoose 5.9.7
- tunnel-ssh 4.1.4
wait about 5 min after, got an error like this.
[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...
DB connect.
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 config.
Host *
ClientAliveInterval 8
ServerAliveInterval 60
TCPKeepAlive yes
Solution
SOLVED
mongoose.connect(URL, {
useNewUrlParser: true,
useUnifiedTopology: true,
useCreateIndex: true,
serverSelectionTimeoutMS: 30000, // Use this.
socketTimeoutMS: 30000 // Use this.
})
Answered By - user11940222