Skip to content

同名の新規ハッシュタグが同時に作られるとサーバーでエラーが発生する #17639

Description

@ihoronir

💡 Summary

同じハッシュタグ(ただし、そのハッシュタグはまだDBに存在しない)を含むノートが同時に複数作成されると、サーバーでエラーが発生します。

エラー例:
ERR  *  [db sql]        INSERT INTO "hashtag"("id", "name", "mentionedUserIds", "mentionedUsersCount", "mentionedLocalUserId...
QueryFailedError: duplicate key value violates unique constraint "IDX_347fec870eafea7b26c8a73bac"
    at PostgresQueryRunner.query (/workspace/node_modules/.pnpm/typeorm@1.0.0_ioredis@5.11.1_pg@8.22.0/node_modules/typeorm/driver/postgres/PostgresQueryRunner.js:231:19)
    at process.processTicksAndRejections (node:internal/process/task_queues:103:5)
    at async InsertQueryBuilder.execute (/workspace/node_modules/.pnpm/typeorm@1.0.0_ioredis@5.11.1_pg@8.22.0/node_modules/typeorm/query-builder/InsertQueryBuilder.js:107:33) {
  query: 'INSERT INTO "hashtag"("id", "name", "mentionedUserIds", "mentionedUsersCount", "mentionedLocalUserIds", "mentionedLocalUsersCount", "mentionedRemoteUserIds", "mentionedRemoteUsersCount", "attachedUserIds", "attachedUsersCount", "attachedLocalUserIds", "attachedLocalUsersCount", "attachedRemoteUserIds", "attachedRemoteUsersCount") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14) RETURNING "mentionedUsersCount", "mentionedLocalUsersCount", "mentionedRemoteUsersCount", "attachedUsersCount", "attachedLocalUsersCount", "attachedRemoteUsersCount"',
  parameters: [
    'ao1bg68tycwi000f',
    'my_new_hashtag',
    [ 'ao1b68wrycwi0003' ],
    1,
    [ 'ao1b68wrycwi0003' ],
    1,
    [],
    0,
    [],
    0,
    [],
    0,
    [],
    0
  ],
  driverError: error: duplicate key value violates unique constraint "IDX_347fec870eafea7b26c8a73bac"
      at /workspace/node_modules/.pnpm/pg@8.22.0/node_modules/pg/lib/client.js:652:17
      at process.processTicksAndRejections (node:internal/process/task_queues:103:5)
      at async PostgresQueryRunner.query (/workspace/node_modules/.pnpm/typeorm@1.0.0_ioredis@5.11.1_pg@8.22.0/node_modules/typeorm/driver/postgres/PostgresQueryRunner.js:196:25)
      at async InsertQueryBuilder.execute (/workspace/node_modules/.pnpm/typeorm@1.0.0_ioredis@5.11.1_pg@8.22.0/node_modules/typeorm/query-builder/InsertQueryBuilder.js:107:33) {
    length: 237,
    severity: 'ERROR',
    code: '23505',
    detail: 'Key (name)=(my_new_hashtag) already exists.',
    hint: undefined,
    position: undefined,
    internalPosition: undefined,
    internalQuery: undefined,
    where: undefined,
    schema: 'public',
    table: 'hashtag',
    column: undefined,
    dataType: undefined,
    constraint: 'IDX_347fec870eafea7b26c8a73bac',
    file: 'nbtinsert.c',
    line: '666',
    routine: '_bt_check_unique'
  },
  length: 237,
  severity: 'ERROR',
  code: '23505',
  detail: 'Key (name)=(my_new_hashtag) already exists.',
  hint: undefined,
  position: undefined,
  internalPosition: undefined,
  internalQuery: undefined,
  where: undefined,
  schema: 'public',
  table: 'hashtag',
  column: undefined,
  dataType: undefined,
  constraint: 'IDX_347fec870eafea7b26c8a73bac',
  file: 'nbtinsert.c',
  line: '666',
  routine: '_bt_check_unique'
}

🥰 Expected Behavior

エラーが発生しない

🤬 Actual Behavior

エラーが発生する

📝 Steps to Reproduce

  1. API経由で同名の新規ハッシュタグを持つ複数のノートを同時に作成する。
  2. サーバーのログを見る

💻 Frontend Environment

* Model and OS of the device(s):
* Browser:
* Server URL:
* Misskey:

🛰 Backend Environment (for server admin)

* Installation Method or Hosting Service:
* Misskey: developブランチ 62f8589c05dda67e7ee151d978e652231e3b7aa7
* Node: devContainerのNode.js
* PostgreSQL: devContainerのPostgreSQL
* Redis: devContainerのRedis
* OS and Architecture: devContainer x86_64

Do you want to address this bug yourself?

  • Yes, I will patch the bug myself and send a pull request

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status
    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions