提问人:Aasai priyan 提问时间:10/31/2023 更新时间:10/31/2023 访问量:24
连接丢失:服务器关闭了连接 (PROTOCOL_CONNECTION_LOST)
Connection lost: The server closed the connection (PROTOCOL_CONNECTION_LOST)
问:
我目前正在使用 Lambda Node 16.X 版本使用无服务器架构,但遇到了以下错误。有没有人可以帮助我解决这个问题?
{
"errorType": "Error",
"errorMessage": "Connection lost: The server closed the connection.",
"code": "PROTOCOL_CONNECTION_LOST",
"message": "Connection lost: The server closed the connection.",
"stack": [
"Error: Connection lost: The server closed the connection.",
" at PromisePoolConnection.query (/opt/nodejs/node_modules/mysql2/promise.js:93:22)",
" at /var/task/index.js:1092:25",
" at processTicksAndRejections (node:internal/process/task_queues:96:5)",
" at async Runtime.handler (/var/task/index.js:1802:17)"
]
}
谢谢
我需要一个解决方案或方法来处理与此问题相关的错误。
答:
1赞
Leeroy Hannigan
10/31/2023
#1
你没有展示你的代码或你想做什么,所以很难回答。但似乎您正在查询 MySQL,并且连接已经过时。
当您使用 Lambda 时,您需要确保在请求处理程序外部建立连接,以便可以在调用之间共享连接。您还可以从创建连接池中受益:
const pool = mysql.createPool({
host: '---',
user: '--',
database: '---',
password: '----'
})
无论如何,与数据库的连接已过时,从而导致此错误。您应该重试以初始化连接,然后重试查询。
评论
0赞
Aasai priyan
10/31/2023
感谢您提供此信息;这对我来说非常有益。
评论