express to use mysql, after running for a long time report read ECONNRESET
Here's what happens when connect and end are used
exports.login = async (req, res, next) => {
try {
const username = req.body.reqdata.username;
const password = req.body.reqdata.password;
const sql = `select * from user where loginid='${username}' and password ='${password}'`;
//console.log(sql)
db.connect()
db.query(sql, (err, results, fields) => {
console.log(results);
console.log(err);
if (err) {
res.send({
err: err.message,
});
}
if (results.length > 0) {
//生成token,并且在返回数据中返回,设置了60S失效的token
const token = jwt.sign(req.body, "dsj", { expiresIn: 36000 });
res.send({
message: 0,
data: results,
token: token,
});
} else {
res.send({
message: 1,
data: results,
});
}
});
db.end()
} catch (err) {
next(err);
}
};
Using connect and end in each request returns only the first request and Cannot enqueue Handshake after invoking quit
If this is not applicable, connect and end run for a period of time when they are enabled, then report read ECONNRESET after a long time.
looked up a lot of articles and tried to call end after every connection. This would result in only the first connection being successful and all subsequent connections failing, even if connect was re-used before each request. Many articles say that removing end and letting mysql drop the connection themselves, However, this will cause a read ECONNRESET after running for some time. Trapped in a dead loop, how to solve the above problems and stable operation?
0 Answer
No answer yet
这家伙很懒,什么都没留下...