Node.js Sequelize错误与查询发送错误:read EconReset
PostgreSQL 9.6.2我从node.js/express.js应用程序发送查询 sequelize提供了,这个例子是findAll 我试着做同样的例子Node.js Sequelize错误与查询发送错误:read EconReset,node.js,postgresql,nodes,sequelize.js,Node.js,Postgresql,Nodes,Sequelize.js,PostgreSQL 9.6.2我从node.js/express.js应用程序发送查询 sequelize提供了,这个例子是findAll 我试着做同样的例子 console.log('user id: ', req.decoded); db.orders.findAll({where: {userId: req.decoded.id}}) .then(function (orders) { console.log('orders from db: ', orders)
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' } }
用户id:{id:2}
功能结束
来自数据库的订单请求错误:{SequelizeConnectionError:read EconReset
位于D:\NodeJSProjects\ParkingHouse\node\u modules\sequelize\lib\dialogs\postgres\connection manager.js:110:20
在连接处。但我找不到答案
db为什么要关闭连接?以及如何修复连接
您正在断开连接。可能您没有在框架中调用next()。或者没有关闭事务。
这种结构没有意义:
.then(function (foundUser) {
return foundUser;
}).catch(function (err) {
//get here the exception
return err;
});
只需删除它,然后将控制器重写为
const user = await authorize(req);
if (!user) {
res.status(401).send('Authorization required');
return next();
}
res.status(200).send('All ok');
next();
如果出现错误,您的框架应该自动为您服务。如果您想手动处理它,请尝试{wait Promise}catch(err){
如果您使用的东西还不支持wait/async,请查看一下,您正在失去连接。可能您没有在框架中调用next()。或者不要关闭事务。
这种结构没有意义:
.then(function (foundUser) {
return foundUser;
}).catch(function (err) {
//get here the exception
return err;
});
只需删除它,然后将控制器重写为
const user = await authorize(req);
if (!user) {
res.status(401).send('Authorization required');
return next();
}
res.status(200).send('All ok');
next();
如果出现错误,您的框架应该自动为您服务。如果您想手动处理它,请尝试{wait Promise}catch(err){
如果您使用的东西还不支持wait/async,那么请查看一下问题出在antivirus F-Secure中,请更改它,然后一切正常。
一些问题:
问题出在防病毒F-Secure中,请更改它,然后一切正常。
一些问题:
我今天也犯了类似的错误
{
error: {
Error: write ECONNRESET at WriteWrap.afterWrite (net.js:788:14) errno: 'ECONNRESET',
code: 'ECONNRESET', syscall: 'write'
}
}
您需要设置数据库最大池或避免同时发送多个
这里有一个线程可以帮助您。我今天也有类似的错误
{
error: {
Error: write ECONNRESET at WriteWrap.afterWrite (net.js:788:14) errno: 'ECONNRESET',
code: 'ECONNRESET', syscall: 'write'
}
}
您需要设置数据库最大池或避免同时发送多个
这里有一个线程可能会对您有所帮助。将来我想在authorize.js中放入更多的逻辑,例如检查地理位置、ip等。我想找到用户,完成逻辑操作,然后将用户返回控制器。因此我希望在authorize.js中期待承诺并与用户合作。将来我想在au中放入更多的逻辑thorize.js,例如检查地理位置、ip等。我想找到用户,完成逻辑操作,然后将用户返回控制器。因此,我想期待承诺,并在authorize.js中与用户合作。