Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Koishi在用户首次发送消息时出现数据库INSERT DUPLICATE ENTRY错误 #621

Closed
Tracked by #615
TimeBather opened this issue Apr 20, 2022 · 2 comments
Closed
Tracked by #615

Comments

@TimeBather
Copy link

TimeBather commented Apr 20, 2022

不管是使用QQ频道Adapter还是Sandbox模拟都会有这个问题

复现方式

  • yarn create koishi 创建koishi项目,开启git集成
  • 安装 guild-adapter等插件,配置频道
  • 用频道账号首次发送信息
  • 问题出现

Environment

koishi start
[I] app Koishi/4.5.2
[I] app apply plugin console
[I] app apply plugin logger
[I] app apply plugin manager
[I] app apply plugin status
[I] app apply plugin database-mysql
[I] app apply plugin dataview
[I] app apply plugin chat
[I] app apply plugin adapter-onebot
[I] app apply plugin adapter-qqguild
[I] app apply plugin echo
[I] app apply plugin sandbox
"@koishijs/plugin-adapter-discord": "^2.0.8",
    "@koishijs/plugin-adapter-onebot": "^4.1.6",
    "@koishijs/plugin-adapter-qqguild": "1.1.2",
    "@koishijs/plugin-adapter-telegram": "^2.2.2",
    "@koishijs/plugin-auth": "1.1.2",
    "@koishijs/plugin-chat": "1.2.3",
    "@koishijs/plugin-console": "^3.2.5",
    "@koishijs/plugin-database-mysql": "4.2.0",
    "@koishijs/plugin-dataview": "^1.2.2",
    "@koishijs/plugin-echo": "1.1.0",
    "@koishijs/plugin-eval": "4.0.4",
    "@koishijs/plugin-logger": "^1.2.2",
    "@koishijs/plugin-manager": "^1.7.0",
    "@koishijs/plugin-sandbox": "1.1.0",
    "@koishijs/plugin-status": "^5.3.5",
    "koishi": "^4.5.2"

Log:

[W] mysql INSERT INTO `channel` (`flag`,`assignee`,`guildId`,`locale`,`name`,`activity`,`platform`,`id`) VALUES (0, '109*****', '210*******', '', '', '{}', 'qqguild', '541****')
[W] app ER_DUP_ENTRY: Duplicate entry '5413659-qqguild' for key 'PRIMARY'
        at MysqlDatabase.query (/www/wwwroot/two-dimension-bot/node_modules/@koishijs/plugin-database-mysql/lib/index.js:264:19)
        at MysqlDatabase.create (/www/wwwroot/two-dimension-bot/node_modules/@koishijs/plugin-database-mysql/lib/index.js:396:31)
        at processTicksAndRejections (internal/process/task_queues.js:95:5)
[W] mysql INSERT INTO `channel` (`flag`,`assignee`,`guildId`,`locale`,`name`,`activity`,`platform`,`id`) VALUES (0, '1094*****', '2101642******', '', '', '{}', 'qqguild', '21016*******')
[W] mysql INSERT INTO `channel` (`flag`,`assignee`,`guildId`,`locale`,`name`,`activity`,`platform`,`id`) VALUES (0, 'sandbox', '#', '', '', '{}', 'sandbox', '#')
[W] session /test
    ER_DUP_ENTRY: Duplicate entry '#-sandbox' for key 'PRIMARY'
        at MysqlDatabase.query (/www/wwwroot/two-dimension-bot/node_modules/@koishijs/plugin-database-mysql/lib/index.js:264:19)
        at MysqlDatabase.create (/www/wwwroot/two-dimension-bot/node_modules/@koishijs/plugin-database-mysql/lib/index.js:396:31)
        at processTicksAndRejections (internal/process/task_queues.js:95:5)
    Middleware stack:
@TimeBather TimeBather changed the title Koishi在用户首次发送消息时 Koishi在用户首次发送消息时出现数据库INSERT DUPLICATE ENTRY错误 Apr 20, 2022
@TimeBather
Copy link
Author

这个似乎在多个平台上都有复现,可能和Koishi的用户系统实现有关?

@TimeBather
Copy link
Author

证实这个bug是由于ObserveChannel函数被调用两次产生的,第一次是由App的Process函数调用,第二次是由chat插件调用,chat插件调用位置如下:
https://github.com/koishijs/koishi/blob/master/plugins/frontend/chat/src/index.ts#L71

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants