qier222 / YesPlayMusic

高颜值的第三方网易云播放器,支持 Windows / macOS / Linux :electron:
https://music.qier222.com
MIT License
29.19k stars 4.28k forks source link

[Bug] /login/qr/check 接口流量消耗异常, 一下午300个G #2093

Closed Siykt closed 1 year ago

Siykt commented 1 year ago

[Bug] /login/qr/check 接口流量消耗异常, 一下午300个G

出现问题

就今天发生的, 听了一下午歌流量没了, 干了300个G

2023-7-14-1689349217462

重现步骤

我vercel已经挂了有点诡异, 歌的话是 Roads

https://github.com/Binaryify/NeteaseCloudMusicApi/issues/1769

Siykt commented 1 year ago

https://github.com/Siykt/YesPlayMusic

我之前的版本在这里

https://github.com/qier222/YesPlayMusic/commit/1b7e33c222f158dba24952445542d1a89b09e0af

Siykt commented 1 year ago

卧槽, 这啥啊, 这样不是只要 result.code === 800 就会递归调用 getQrCodeKey 里的 setInterval 一直发请求 ??!!:

src/views/loginAccount.vue:232

getQrCodeKey() {
return loginQrCodeKey().then(result => {
if (result.code === 200) {
// ...
}
this.checkQrCodeLogin();
});
},
checkQrCodeLogin() {
this.qrCodeCheckInterval = setInterval(() => {
if (this.qrCodeKey === '') return;
loginQrCodeCheck(this.qrCodeKey).then(result => {
if (result.code === 800) {
this.getQrCodeKey(); // 重新生成QrCode
this.qrCodeInformation = '二维码已失效,请重新扫码';
}
//...
});
}, 1000);
},

解决方案

// 这里需要clearInterval
this.qrCodeCheckInterval = setInterval(() => {
Jeamorg commented 1 year ago

这是云函数执行时间的可用余额用完了,根据我的测试,如果开启一个登录页面24小时,所耗流量不到400MB。

Siykt commented 1 year ago

这是云函数执行时间的可用余额用完了,根据我的测试,如果开启一个登录页面24小时,所耗流量不到400MB。

目前我调用它这个的地方也就只有这个music项目, 它这种循环的方式是线性提升的, loginQrCodeCheck 只要不符合预期它就会创建一个每秒轮询的定时器, 所以下一次就是每秒 2 次的请求, 接着就是 4 8 16 32... 而且就算返回正常的结果, 之前的定时器也不会被清除