altairwei / WizNotePlus

A community-driven cross-platform note-taking client.
https://altairwei.github.io/WizNotePlus/
Other
578 stars 87 forks source link

系统睡眠/休眠后再次启动以后WizNotePlus提示网络错误无法同步 #265

Open turtleizzy opened 1 month ago

turtleizzy commented 1 month ago

系统挂起、睡眠或休眠以后,再次进入系统以后不论网络连接情况如何,WizNotePlus都提示网络错误无法同步(-1),需要关闭软件重新进入才能解决。

环境:Linux Mint 22(Ubuntu 24.04) 版本:v2.12.0 (AppImage),其他既往版本也有同样现象

altairwei commented 1 month ago

下次碰到这种情况,记得把日志贴出来让我看看。

turtleizzy commented 1 month ago
Version: WizNote QTLINUX 2.12.0
Username: ***@gmail.com
Time: 2024-10-21 15:32:44

2024-10-21T15:16:27: [Sync] "----------同步群组----------"
2024-10-21T15:16:27: [Sync] "----------下载笔记内容----------"
2024-10-21T15:16:27: [Sync] "----------同步完成----------"
2024-10-21T15:31:14: application message received :  "WIZ_SINGLE_APPLICATION"
2024-10-21T15:31:31: [Sync] syncing all started, thread: 0x7d37b16006c0
2024-10-21T15:31:31: client version: QTLINUX(2.12.0)
2024-10-21T15:31:31: [Sync] Syncing all notes...
2024-10-21T15:31:31: Can't exec request, ret code=301, message=Invalid token, externCode=
2024-10-21T15:31:31: Failed to call /as/user/keep
2024-10-21T15:31:40: "对象在路径“/org/freedesktop/NetworkManager/ActiveConnection/6”处不存在"
2024-10-21T15:32:33: network status check,  downloaded bytes :  0   last time :  0  uploaded bytes :  0  last time :  0
2024-10-21T15:32:33: [sync]Xml rpc event loop time out
2024-10-21T15:32:33: Failed to exec json request, network error=5, message=Event loop time out, can not get response from network reply, url=https://as.wiz.cn/as/user/token?clientType=macos&clientVersion=2.12.0&apiVersion=10&token=****&srcHost=as.wiz.cn
2024-10-21T15:32:33: Failed to create account

下次碰到这种情况,记得把日志贴出来让我看看。

刚刚顺手重现了一下。

altairwei commented 1 month ago

看起来像是 token 过期后,重新获取,但不知为什么请求的是创建账务的 API。

你使用的是官方服务器吧?

turtleizzy commented 1 month ago

看起来像是 token 过期后,重新获取,但不知为什么请求的是创建账务的 API。

你使用的是官方服务器吧?

是的,我刚又点了两回同步,log是这样的。 以及从log来看像是网络本身超时了,这个也挺神奇的。

2024-10-21T15:38:41: [Sync] syncing all started, thread: 0x7d37b16006c0
2024-10-21T15:38:41: client version: QTLINUX(2.12.0)
2024-10-21T15:38:41: Failed to exec json request, network error=99, message=, url=https://as.wiz.cn/as/user/keep?clientType=macos&clientVersion=2.12.0&apiVersion=10&token=***&srcHost=as.wiz.cn
2024-10-21T15:38:41: Failed to call /as/user/keep
2024-10-21T15:38:41: Failed to exec json request, network error=99, message=, url=https://as.wiz.cn/as/user/token?clientType=macos&clientVersion=2.12.0&apiVersion=10&token=***&srcHost=as.wiz.cn
2024-10-21T15:38:41: Failed to create account
2024-10-21T15:38:41: [Sync] Syncing all notes...
2024-10-21T15:38:47: [Sync] syncing all started, thread: 0x7d37b16006c0
2024-10-21T15:38:47: client version: QTLINUX(2.12.0)
2024-10-21T15:38:47: Failed to exec json request, network error=99, message=, url=https://as.wiz.cn/as/user/keep?clientType=macos&clientVersion=2.12.0&apiVersion=10&token=***&srcHost=as.wiz.cn
2024-10-21T15:38:47: Failed to call /as/user/keep
2024-10-21T15:38:47: [Sync] Syncing all notes...
2024-10-21T15:38:47: Failed to exec json request, network error=99, message=, url=https://as.wiz.cn/as/user/token?clientType=macos&clientVersion=2.12.0&apiVersion=10&token=***&srcHost=as.wiz.cn
altairwei commented 1 month ago

我检查了下源代码,Failed to create account 只是 log 消息写错了,实际上就是 https://as.wiz.cn/as/user/token 这个 API 请求失败。

turtleizzy commented 1 month ago

我检查了下源代码,Failed to create account 只是 log 消息写错了,实际上就是 https://as.wiz.cn/as/user/token 这个 API 请求失败。

嗯嗯,但事实上网络是通的(不然也没办法回复),所以问题似乎还是在发起网络连接的客户端上?

altairwei commented 1 month ago

有可能是官方服务器改了 API?不允许通过 https://as.wiz.cn/as/user/token 刷新 token?

altairwei commented 1 month ago

你可以在自己测试下这个 API,参考你的日志,POST 这个 API 看看返回是否正常。

altairwei commented 1 month ago

或者抓包看看到底是哪里有问题。我这边主要是难以复现你的情况。

turtleizzy commented 1 month ago

你可以在自己测试下这个 API,参考你的日志,POST 这个 API 看看返回是否正常。

我用curl直接POST了一下那个地址,返回405 Method Not Allowed

curl -v -X POST https://as.wiz.cn/as/user/keep\?clientType\=macos\&clientVersion\=2.12.0\&apiVersion\=10\&token\=***\&srcHost\=as.wiz.cn

> POST /as/user/keep?clientType=macos&clientVersion=2.12.0&apiVersion=10&token=***&srcHost=as.wiz.cn HTTP/2
> Host: as.wiz.cn
> User-Agent: curl/8.5.0
> Accept: */*
> 
< HTTP/2 405 
< date: Mon, 21 Oct 2024 07:56:23 GMT
< content-type: text/plain; charset=utf-8
< content-length: 18
< access-control-allow-credentials: true
< access-control-allow-methods: GET,POST,PUT,DELETE,OPTIONS
< access-control-allow-headers: Cache-Control, Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With, X-Wiz-Referer, X-Wiz-Token, wiz-auto-login-param, X-Wiz-Digest, x-wiz-office-token, x-wiz-cloud-token
< allow: HEAD, GET
< 
* Connection #0 to host as.wiz.cn left intact

GET可以正常返回

< HTTP/2 200 
< date: Mon, 21 Oct 2024 08:00:09 GMT
< content-type: application/json; charset=utf-8
< content-length: 128
< access-control-allow-credentials: true
< access-control-allow-methods: GET,POST,PUT,DELETE,OPTIONS
< access-control-allow-headers: Cache-Control, Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With, X-Wiz-Referer, X-Wiz-Token, wiz-auto-login-param, X-Wiz-Digest, x-wiz-office-token, x-wiz-cloud-token
< 
* Connection #0 to host as.wiz.cn left intact
{"returnCode":301,"returnMessage":"Invalid token","externCode":"","code":301,"return_code":301,"return_message":"Invalid token"}
altairwei commented 1 month ago

不是 keep,而是测试 https://as.wiz.cn/as/user/token 这个 API,keep 是正常的。

altairwei commented 1 month ago

POST 带上两个数据:userId 和 password

Url Query 是这几个:clientType=macos&clientVersion=2.12.0&apiVersion=10&token=你的旧token&srcHost=as.wiz.cn

turtleizzy commented 1 month ago

不是 keep,而是测试 https://as.wiz.cn/as/user/token 这个 API,keep 是正常的。

这个token API的POST是正常的,返回

{"returnCode":301,"returnMessage":"Invalid token","externCode":"","code":301,"return_code":301,"return_message":"Invalid token"}
altairwei commented 1 month ago

Post 带上你的账号密码了吗?旧 token 填到了 url query 里了吗?

altairwei commented 1 month ago

as/user/keep 失败是因为断网太久,token 失效,所以不能 keep

所以才需要通过 as/user/token 用账号密码重新拿 token

turtleizzy commented 1 month ago

Post 带上你的账号密码了吗?旧 token 填到了 url query 里了吗?

不好意思回复太快了,刚发完了才看到你后面那条,带上data和content type: json之后可以正常得到token

{"returnCode":200,"returnMessage":"OK","externCode":"","return_code":200,"return_message":"success","result":...}
altairwei commented 1 month ago

那看来 API 是正常的。你可能需要抓包,来判断 WizNotePlus POST as/user/token 时到底发生了什么导致失败。

turtleizzy commented 1 month ago

那看来 API 是正常的。你可能需要抓包,来判断 WizNotePlus POST as/user/token 时到底发生了什么导致失败。

我大致用ptcpdump抓了一下,我这边as.wiz.cn解析的ip是120.55.138.92。


16:30:41.119511 wlo1 Out IP (tos 0x0, ttl 64, id 62204, offset 0, flags [DF], proto TCP (6), length 60)
    192.168.2.133.34298 > 120.55.138.92.80: Flags [S], cksum 0xc5ef, seq 2630781574, win 64240, options [mss 1460,sackOK,TS val 3483433711 ecr 0,nop,wscale 7], length 0
    Process (pid 139022, cmd /tmp/.mount_WizNotGqfIfj/usr/bin/WizNotePlus, args /home/abc/Applications/WizNotePlus-linux-v2.12.0.AppImage)
    ParentProc (pid 3389, cmd /usr/bin/cinnamon, args cinnamon --replace)
16:30:41.237427 wlo1 In IP (tos 0x4, ttl 47, id 0, offset 0, flags [DF], proto TCP (6), length 52)
    120.55.138.92.80 > 192.168.2.133.34298: Flags [S.], cksum 0x9ada, seq 916568181, ack 2630781575, win 29200, options [mss 1360,nop,nop,sackOK,nop,wscale 9], length 0
    Process (pid 139022, cmd /tmp/.mount_WizNotGqfIfj/usr/bin/WizNotePlus, args /home/abc/Applications/WizNotePlus-linux-v2.12.0.AppImage)
    ParentProc (pid 3389, cmd /usr/bin/cinnamon, args cinnamon --replace)
16:30:41.237552 wlo1 Out IP (tos 0x0, ttl 64, id 62205, offset 0, flags [DF], proto TCP (6), length 40)
    192.168.2.133.34298 > 120.55.138.92.80: Flags [.], cksum 0xc5db, seq 2630781575, ack 916568182, win 502, length 0
    Process (pid 139022, cmd /tmp/.mount_WizNotGqfIfj/usr/bin/WizNotePlus, args /home/abc/Applications/WizNotePlus-linux-v2.12.0.AppImage)
    ParentProc (pid 3389, cmd /usr/bin/cinnamon, args cinnamon --replace)
16:30:41.237621 wlo1 Out IP (tos 0x0, ttl 64, id 62206, offset 0, flags [DF], proto TCP (6), length 40)
    192.168.2.133.34298 > 120.55.138.92.80: Flags [F.], cksum 0xc5db, seq 2630781575, ack 916568182, win 502, length 0
    Process (pid 139022, cmd /tmp/.mount_WizNotGqfIfj/usr/bin/WizNotePlus, args /home/abc/Applications/WizNotePlus-linux-v2.12.0.AppImage)
    ParentProc (pid 3389, cmd /usr/bin/cinnamon, args cinnamon --replace)
16:30:41.348755 wlo1 In IP (tos 0x4, ttl 47, id 56207, offset 0, flags [DF], proto TCP (6), length 40)
    120.55.138.92.80 > 192.168.2.133.34298: Flags [F.], cksum 0x4d1f, seq 916568182, ack 2630781576, win 58, length 0
    Process (pid 139022, cmd /tmp/.mount_WizNotGqfIfj/usr/bin/WizNotePlus, args /home/abc/Applications/WizNotePlus-linux-v2.12.0.AppImage)
    ParentProc (pid 3389, cmd /usr/bin/cinnamon, args cinnamon --replace)
16:30:41.348914 wlo1 Out IP (tos 0x0, ttl 64, id 62207, offset 0, flags [DF], proto TCP (6), length 40)
    192.168.2.133.34298 > 120.55.138.92.80: Flags [.], cksum 0xc5db, seq 2630781576, ack 916568183, win 502, length 0
    Process (pid 139022, cmd /tmp/.mount_WizNotGqfIfj/usr/bin/WizNotePlus, args /home/abc/Applications/WizNotePlus-linux-v2.12.0.AppImage)
    ParentProc (pid 3389, cmd /usr/bin/cinnamon, args cinnamon --replace)
``
altairwei commented 1 month ago

这个嘛看不出来啥东西。我主要是想看看 HTTP 请求返回的是什么。

altairwei commented 1 month ago

你注意到第一个日志信息中的:"对象在路径“/org/freedesktop/NetworkManager/ActiveConnection/6”处不存在"

这可能是 Linux 的某种问题,但我不太熟悉。

altairwei commented 1 month ago

我从客户端代码看不错有任何错误的地方,API 也能正常访问。那么错误的可能就是 Linux 的某种配置了。

turtleizzy commented 1 month ago

这个嘛看不出来啥东西。我主要是想看看 HTTP 请求返回的是什么。

图片

我用wireshark打开了一下捕获的包,里面没什么内容。

你注意到第一个日志信息中的:"对象在路径“/org/freedesktop/NetworkManager/ActiveConnection/6”处不存在"

这可能是 Linux 的某种问题,但我不太熟悉。

了解,我再自己研究一下,多谢!

turtleizzy commented 1 month ago

由于我的log中出现了network error=99,这个在QNetworkReply中是UnknownNetworkError,我搜了一下好像确实有人存在类似情况(ref: 1),根据这个帖子的回复,似乎需要把QNetworkAccessManager实例删除再创建可以解决这个问题,大概在源代码的这个位置:https://github.com/altairwei/WizNotePlus/blob/3cae06fbd0eaa5147e5b307a428af359bceb47f5/src/share/WizRequest.cpp#L39

  1. https://forum.qt.io/topic/136305/qt-c-application-results-qnetworkreply-unknownnetworkerror-error-after-network-restart
altairwei commented 1 month ago

从你的第一个日志来看,实际上就是网络连接超时:

2024-10-21T15:32:33: network status check,  downloaded bytes :  0   last time :  0  uploaded bytes :  0  last time :  0
2024-10-21T15:32:33: [sync]Xml rpc event loop time out
2024-10-21T15:32:33: Failed to exec json request, network error=5, message=Event loop time out, can not get response from network reply, url=https://as.wiz.cn/as/user/token?clientType=macos&clientVersion=2.12.0&apiVersion=10&token=****&srcHost=as.wiz.cn
altairwei commented 1 month ago

你这个问题,我在 Linux 上使用 WizNotePlus 的时候几乎没碰到过。