XMOJ-Script-dev / XMOJ-bbs

XMOJ增强脚本后台
https://api.xmoj-bbs.me
GNU Affero General Public License v3.0
5 stars 1 forks source link

[Bug] 表查询没有锁定 #3

Closed langningchen closed 1 year ago

langningchen commented 1 year ago

检查项

描述

错误:数据库查询失败:Error: D1_ERROR: UNIQUE constraint failed: phpsessid.token

原因是表被多个请求同时查询

重现步骤

清楚 cookies ,然后直接在讨论区刷新

控制台错误信息

No response

boomzero commented 1 year ago

Unique 可以去掉?

On Oct 17, 2023, at 21:28, Chen LangNing @.***> wrote:

检查项

我已确认了XMOJ增强脚本已为最新版,且最新版未修复这个 Bug 。 我已在 Issues 页面 https://github.com/XMOJ-Script-dev/XMOJ-Script/issues 中搜索,确认了这一 Bug 未被提交过。 描述

错误:数据库查询失败:Error: D1_ERROR: UNIQUE constraint failed: phpsessid.token

原因是表被多个请求同时查询

重现步骤

清楚 cookies ,然后直接在讨论区刷新

控制台错误信息

No response

— Reply to this email directly, view it on GitHub https://github.com/XMOJ-Script-dev/XMOJ-bbs/issues/3, or unsubscribe https://github.com/notifications/unsubscribe-auth/AULMJZIIRAM46LMXD25QS3DX72BZNAVCNFSM6AAAAAA6D3M6RSVHI2DSMVQWIX3LMV43ASLTON2WKOZRHE2DONBTHA2TKMA. You are receiving this because you were assigned.

PythonSmall-Q commented 1 year ago

langningchen commented 1 year ago

如果去掉可能会引起问题,我认为应该是用表锁定

langningchen commented 1 year ago

用互斥锁

boomzero commented 1 year ago

很老的issue, 我以前做hash phpsessid时就有

boomzero commented 1 year ago

...为什么这个消息发错issue了

boomzero commented 1 year ago

@langningchen

...

boomzero commented 1 year ago

用互斥锁

@langningchen ~什么是互斥锁~

langningchen commented 1 year ago

@langningchen ~什么是互斥锁~

@boomzero bdfs (baidu first search)

langningchen commented 1 year ago

这有一篇文章讲得很好: https://zhuanlan.zhihu.com/p/161010435?utm_id=0

就是怕你看不懂

boomzero commented 1 year ago

@langningchen 不会

langningchen commented 1 year ago

@langningchen 不会

好吧,那么就在插入之前检查一下有没有相同的项,如果有就不插入了

langningchen commented 1 year ago

@boomzero 互斥锁对你来说可能是有点难了

boomzero commented 1 year ago

https://github.com/XMOJ-Script-dev/XMOJ-bbs/commit/7f9fc2981ecfca5e95cb16015b07f1a63eacc990

boomzero commented 1 year ago

@langningchen

langningchen commented 12 months ago

@boomzero 也可以