下次验证生产中偶尔出现500错误

问题描述 投票:0回答:1

我正在开发一个 nextjs 项目(https://recurwallet.vercel.app),它连接到 mongodb atlas。

它在 localhost 中运行良好,但在 Vercel 部署中偶尔我会在下次身份验证时收到此错误。

我不认为用户会话已过期,因为有时我会在很长时间后尝试该应用程序,但它似乎仍然处于活动状态

无法理解问题所在。粘贴日志如下:

[GET] /api/auth/session?nxtPnextauth=session status=500

Unhandled Rejection: MongoServerSelectionError: Server selection timed out after 30000 ms
at Timeout._onTimeout (/var/task/node_modules/mongodb/lib/sdam/topology.js:278:38)
at listOnTimeout (node:internal/timers:573:17)
at process.processTimers (node:internal/timers:514:7) {
reason: TopologyDescription {
type: 'ReplicaSetNoPrimary',
servers: Map(3) {
'ac-6f2vd8f-shard-00-02.wo509tr.mongodb.net:27017' => [ServerDescription],
'ac-6f2vd8f-shard-00-00.wo509tr.mongodb.net:27017' => [ServerDescription],
'ac-6f2vd8f-shard-00-01.wo509tr.mongodb.net:27017' => [ServerDescription]
},
stale: false,
compatible: true,
heartbeatFrequencyMS: 10000,
localThresholdMS: 15,
setName: 'atlas-r1jdn2-shard-0',
maxElectionId: null,
maxSetVersion: null,
commonWireVersion: 0,
logicalSessionTimeoutMinutes: null
},
code: undefined,
[Symbol(errorLabels)]: Set(0) {}
}
Node.js process exited with exit status: 128. The logs above can help with debugging the issue.
Unknown application error occurred
mongodb next.js next-auth
1个回答
0
投票

您可能没有在 mongodb 中配置白名单 ip。

Whitelist Ip
仅允许预先批准的 IP 地址列表中的人员访问网络服务。

在生产中,您创建了一个新的云 mongodb 图集,并且您的应用程序正在连接到该图集。据我所知,当您在 MongoDB Atlas 中创建新集群时,默认没有列入白名单的 IP 地址。

如果您将

0.0.0.0/0
添加到白名单,它将允许来自任何地方的任何人

© www.soinside.com 2019 - 2024. All rights reserved.