PostgreSQL 9.6.2我從node.js/express.js應用程序發送查詢。發送查詢時出現Sequelize錯誤錯誤:讀取ECONNRESET
該續集提供了doc how to make the query,這個例子findAll。
我試着做出同樣的例子。
console.log('user id: ', req.decoded);
db.orders.findAll({where: {userId: req.decoded.id}})
.then(function (orders) {
console.log('orders from db: ', orders);
})
.catch(function (err) {
console.log('orders request error from db: ', err);
});
console.log('end of function');
控制檯日誌:
user id: { id: 2 }
end of function
orders request error from db: { SequelizeConnectionError: read ECONNRESET
at D:\NodeJSProjects\ParkingHouse\node_modules\sequelize\lib\dialects\postgres\connection-manager.js:110:20
at Connection.<anonymous> (D:\NodeJSProjects\ParkingHouse\node_modules\pg\lib\client.js:186:5)
at emitOne (events.js:96:13)
at Connection.emit (events.js:188:7)
at Socket.<anonymous> (D:\NodeJSProjects\ParkingHouse\node_modules\pg\lib\connection.js:86:10)
at emitOne (events.js:96:13)
at Socket.emit (events.js:188:7)
at emitErrorNT (net.js:1278:8)
at _combinedTickCallback (internal/process/next_tick.js:74:11)
at process._tickCallback (internal/process/next_tick.js:98:9)
name: 'SequelizeConnectionError',
message: 'read ECONNRESET',
parent:
{ Error: read ECONNRESET
at exports._errnoException (util.js:1022:11)
at TCP.onread (net.js:569:26) code: 'ECONNRESET', errno: 'ECONNRESET', syscall: 'read' },
original:
{ Error: read ECONNRESET
at exports._errnoException (util.js:1022:11)
at TCP.onread (net.js:569:26) code: 'ECONNRESET', errno: 'ECONNRESET', syscall: 'read' } }
一段時間後,該請求被重複,然後我從數據庫獲取數據。 我找到了類似的主題Node js ECONNRESET但我沒有找到答案。
- db爲什麼關閉連接?以及如何修復它。
未來我想把更多的邏輯放到authorize.js中,例如檢查地理位置,ip等。我想找到用戶,完成邏輯操作,然後將用戶返回給控制器。所以我想期待承諾,並在authorize.js中與用戶一起工作。 –