Diving-Fish / maimaidx-prober

舞萌 DX 查分器
https://www.diving-fish.com/maimaidx/prober
MIT License
681 stars 52 forks source link

未知原因闪退 #89

Closed Kuro96 closed 1 year ago

Kuro96 commented 1 year ago

环境

程序版本

在以下两个版本中均出现闪退情况:

  1. 官方编译1.3.0
  2. 官方编译1.2.1

如何复现

  1. 参照本项目readme完成“1. 准备工作”
  2. 双击运行程序,打开电脑版微信,进入舞萌 DX 公众号,点击我的记录
  3. 切换到代理服务器的控制台界面,等待导入完成

预期结果

成功导入数据并可通过舞萌 DX | 中二节奏查分器查询

实际所得

Kuro96 commented 1 year ago

通过git bash运行得到相关报错信息:

$ ./maimaidx-prober-proxy-windows-amd64-1.3.0.exe
2023/07/03 14:53:53 INFO: 您使用的是最新版本。
2023/07/03 14:53:53 INFO: 登录成功
2023/07/03 14:53:53 INFO: 使用此软件则表示您同意共享您在微信公众号舞萌 DX、中二节奏中的数据。
2023/07/03 14:53:53 INFO: 您可以在微信客户端访问微信公众号舞萌 DX、中二节奏的个人信息主页进行分数导入,如需退出请直接关闭程序或按下 Ctrl + C
2023/07/03 14:53:53 INFO: 代理设置已自动修改。
2023/07/03 14:53:53 INFO: 代理已开启到 127.0.0.1:8033
2023/07/03 14:53:58 INFO: 正在导入 Basic 难度……
2023/07/03 14:54:00 INFO: 导入成功
2023/07/03 14:54:00 INFO: 正在导入 Advanced 难度……
2023/07/03 14:54:03 INFO: 导入成功
2023/07/03 14:54:03 INFO: 正在导入 Expert 难度……
2023/07/03 14:54:16 [007] WARN: Error copying to client: readfrom tcp 10.32.19.234:6787->202.89.233.100:443: read tcp 127.0.0.1:8033->127.0.0.1:6786: wsarecv: An existing connection was forcibly closed by the remote host.
2023/07/03 14:54:16 [007] WARN: Error copying to client: readfrom tcp 127.0.0.1:8033->127.0.0.1:6786: write tcp 127.0.0.1:8033->127.0.0.1:6786: wsasend: An existing connection was forcibly closed by the remote host.
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x0 addr=0x40 pc=0xe003e6]

goroutine 32 [running]:
main.(*proberAPIClient).commit(0xc000086180, {0xc00066c000, 0xf47ae, 0x110000})
        github.com/Diving-Fish/maimaidx-prober/proxy/cmd/maimaidx-prober-proxy/prober_api.go:54 +0xc6
main.(*proberAPIClient).fetchDataMaimai(0xc000086180, 0xc00025c500, {0xc00000a008, 0x1, 0x1})
        github.com/Diving-Fish/maimaidx-prober/proxy/cmd/maimaidx-prober-proxy/prober_api.go:98 +0x679
created by main.(*proxyContext).handleResponse
        github.com/Diving-Fish/maimaidx-prober/proxy/cmd/maimaidx-prober-proxy/proxy.go:51 +0x5ef
Diving-Fish commented 1 year ago

看来还是要整理下代码把错误处理弄一起……有点一坨了

xen0n commented 1 year ago

详细描述问题的 po 主事鉴

Janet-Baker commented 1 year ago

panic位置: https://github.com/Diving-Fish/maimaidx-prober/blob/e59c669024175b2f9385656b66f68c77bb7b7716/proxy/cmd/maimaidx-prober-proxy/prober_api.go#L86

前面其实已经出问题了: https://github.com/Diving-Fish/maimaidx-prober/blob/e59c669024175b2f9385656b66f68c77bb7b7716/proxy/cmd/maimaidx-prober-proxy/prober_api.go#L82-L83net/http: TLS handshake timeout

然而,错误判断却写在了它后面: https://github.com/Diving-Fish/maimaidx-prober/blob/e59c669024175b2f9385656b66f68c77bb7b7716/proxy/cmd/maimaidx-prober-proxy/prober_api.go#L87-L89


当然,由于华立服务器很不稳定,每一次错误的位置和种类也不一定一样…… 都来体验一下土豆服务器的快乐吧

xen0n commented 1 year ago

正常的话应该不放过任何一个可能的 err 返回,然后尽量在最上层集中处理错误(因为这个简单场景其实不需要专门关心、单独处理每一条路径可能的每一种错误),基本就是接住之后触发重试即可。如果担心 panic 那么也总是可以套一层 goroutine 然后 defer 块里 recover() 检查并同样触发重试。

也就是写 Go 可以方便地静默无视错误了。比方说 Rust 的错误处理你要么写 ?(这意味着你会把 Err 抛到上一层)要么 unwrap()(这会十分扎眼,并且很明显每处这种地方,万一确实错误了进程就会崩溃)。总之要说国服 maimai NET 是错误处理的试金石也没什么问题

Diving-Fish commented 1 year ago

学到虚脱