[英]In windows, stopping postgres service causes node to crash with “error : terminating connection due to administrator command”
Scenario 1: postgres service not running. 方案1:postgres服务未运行。 node start. 节点启动。 rest calls times out => no issues 休息电话超时=>没有问题
Scenario 2: postgres service not running. 方案2:postgres服务未运行。 node start. 节点启动。 postgres service start. postgres服务启动。 rest calls work => no issues 休息电话工作=>没有问题
Scenario 3: postgres service not running. 方案3:postgres服务未运行。 node start. 节点启动。 postgres service start. postgres服务启动。 rest calls work. 休息电话工作。 postgres service stop => node crash. postgres服务停止=>节点崩溃。
Stack trace when this happens is given below: 发生这种情况时的堆栈跟踪如下:
error: terminating connection due to administrator command at Connection.parseE (...\\express.js\\node_modules\\pg\\lib\\connection.js:553:11) at Connection.parseMessage (...\\express.js\\node_modules\\pg\\lib\\connection.js:378:19) at Socket. 错误:由于Connection.parseMessage(... \\ express.js \\ node_modules \\)上Connection.parseE(... \\ express.js \\ node_modules \\ pg \\ lib \\ connection.js:553:11)的管理员命令而终止连接pg \\ lib \\ connection.js:378:19)。 (...\\express.js\\node_modules\\pg\\lib\\connection.js:119:22) at emitOne (events.js:116:13) at Socket.emit (events.js:211:7) at addChunk (_stream_readable.js:263:12) at readableAddChunk (_stream_readable.js:250:11) at Socket.Readable.push (_stream_readable.js:208:10) at TCP.onread (net.js:594:20) (... \\ express.js \\ node_modules \\ pg \\ lib \\ connection.js:119:22)在Socket.emit(events.js:211:7)上的sendOne(events.js:116:13)在addChunk( TCP.onread(net.js:594:20)上Socket.Readable.push(_stream_visible.js:208:10)上的可读AddChunk(_stream_visible.js:250:11)上的_stream_visible.js:263:12)
I am using Postgres Pool with the following config: 我正在使用具有以下配置的Postgres Pool:
const pool = new Pool({
user: 'postgres',
host: 'localhost',
database: 'sampleDB',
password: 'password',
port: 5432,
max: 1,
idleTimeoutMillis: 30000,
connectionTimeoutMillis: 2000,
})
How do I handle this case so that node won't crash and can go back to Scenario-1 and then move to Scenario-2 ? 我如何处理这种情况,以使节点不会崩溃,并且可以返回到方案1,然后再移至方案2?
After going through the documentation of node-postgres( link ), I figured out a way to capture this error and avoid node crash. 阅读完node-postgres( link )的文档后,我想出了一种捕获此错误并避免节点崩溃的方法。
pool.on('error', (err, client) => {
console.log('postgres connection error : ' + err)
})
Adding the above code will allow node to handle the error and not crash. 添加以上代码将使节点能够处理错误,而不会崩溃。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.