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

System address book creation errors on concurrent user creation #41996

Closed
juliusknorr opened this issue Dec 4, 2023 · 9 comments · Fixed by #42052
Closed

System address book creation errors on concurrent user creation #41996

juliusknorr opened this issue Dec 4, 2023 · 9 comments · Fixed by #42052
Assignees
Labels
3. to review Waiting for reviews 29-feedback bug feature: carddav Related to CardDAV internals feature: dav

Comments

@juliusknorr
Copy link
Member

juliusknorr commented Dec 4, 2023

So this sounds like an edge case I just trigger with automatically configuring my dev setup, but still worth to report

Steps to reproduce:

  • Install a new Nextcloud instance through occ
  • call multiple occ user:add in parallel

An exception occurred while executing a query: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'principals/system/system-system' for key 'addressbook_index'

@ChristophWurst Do I read the trace correctly that this happens only because the system address book was not created initially and is then trying to get created by each of the occ user:add calls?

{
  "reqId": "VpkednLd2tMVnO4SA1QG",
  "level": 3,
  "time": "2023-12-04T09:52:36+00:00",
  "remoteAddr": "",
  "user": "--",
  "app": "no app in context",
  "method": "",
  "url": "--",
  "message": "Exception thrown: Doctrine\\DBAL\\Exception\\UniqueConstraintViolationException",
  "userAgent": "--",
  "version": "29.0.0.2",
  "exception": {
    "Exception": "Doctrine\\DBAL\\Exception\\UniqueConstraintViolationException",
    "Message": "An exception occurred while executing a query: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'principals/system/system-system' for key 'addressbook_index'",
    "Code": 1062,
    "Trace": [
      {
        "file": "/var/www/html/3rdparty/doctrine/dbal/src/Connection.php",
        "line": 1938,
        "function": "convert",
        "class": "Doctrine\\DBAL\\Driver\\API\\MySQL\\ExceptionConverter",
        "type": "->",
        "args": [
          [
            "Doctrine\\DBAL\\Driver\\PDO\\Exception"
          ],
          [
            "Doctrine\\DBAL\\Query"
          ]
        ]
      },
      {
        "file": "/var/www/html/3rdparty/doctrine/dbal/src/Connection.php",
        "line": 1880,
        "function": "handleDriverException",
        "class": "Doctrine\\DBAL\\Connection",
        "type": "->",
        "args": [
          [
            "Doctrine\\DBAL\\Driver\\PDO\\Exception"
          ],
          [
            "Doctrine\\DBAL\\Query"
          ]
        ]
      },
      {
        "file": "/var/www/html/3rdparty/doctrine/dbal/src/Connection.php",
        "line": 1208,
        "function": "convertExceptionDuringQuery",
        "class": "Doctrine\\DBAL\\Connection",
        "type": "->",
        "args": [
          [
            "Doctrine\\DBAL\\Driver\\PDO\\Exception"
          ],
          "INSERT INTO `oc_addressbooks` (`uri`, `displayname`, `description`, `principaluri`, `synctoken`) VALUES(?, ?, ?, ?, ?)",
          [
            "*** sensitive parameters replaced ***",
            "*** sensitive parameters replaced ***",
            "System addressbook which holds all users of this instance",
            "*** sensitive parameters replaced ***",
            1
          ],
          []
        ]
      },
      {
        "file": "/var/www/html/lib/private/DB/Connection.php",
        "line": 294,
        "function": "executeStatement",
        "class": "Doctrine\\DBAL\\Connection",
        "type": "->",
        "args": [
          "INSERT INTO `oc_addressbooks` (`uri`, `displayname`, `description`, `principaluri`, `synctoken`) VALUES(?, ?, ?, ?, ?)",
          [
            "*** sensitive parameters replaced ***",
            "*** sensitive parameters replaced ***",
            "System addressbook which holds all users of this instance",
            "*** sensitive parameters replaced ***",
            1
          ],
          []
        ]
      },
      {
        "file": "/var/www/html/3rdparty/doctrine/dbal/src/Query/QueryBuilder.php",
        "line": 386,
        "function": "executeStatement",
        "class": "OC\\DB\\Connection",
        "type": "->",
        "args": [
          "INSERT INTO `oc_addressbooks` (`uri`, `displayname`, `description`, `principaluri`, `synctoken`) VALUES(:uri, :displayname, :description, :principaluri, :synctoken)",
          [
            "*** sensitive parameters replaced ***",
            "System addressbook which holds all users of this instance",
            "*** sensitive parameters replaced ***",
            "*** sensitive parameters replaced ***",
            1
          ],
          []
        ]
      },
      {
        "file": "/var/www/html/lib/private/DB/QueryBuilder/QueryBuilder.php",
        "line": 280,
        "function": "execute",
        "class": "Doctrine\\DBAL\\Query\\QueryBuilder",
        "type": "->",
        "args": []
      },
      {
        "file": "/var/www/html/apps/dav/lib/CardDAV/CardDavBackend.php",
        "line": 436,
        "function": "execute",
        "class": "OC\\DB\\QueryBuilder\\QueryBuilder",
        "type": "->",
        "args": []
      },
      {
        "file": "/var/www/html/lib/public/AppFramework/Db/TTransactional.php",
        "line": 63,
        "function": "OCA\\DAV\\CardDAV\\{closure}",
        "class": "OCA\\DAV\\CardDAV\\CardDavBackend",
        "type": "->",
        "args": [
          "*** sensitive parameters replaced ***"
        ]
      },
      {
        "file": "/var/www/html/apps/dav/lib/CardDAV/CardDavBackend.php",
        "line": 443,
        "function": "atomic",
        "class": "OCA\\DAV\\CardDAV\\CardDavBackend",
        "type": "->",
        "args": [
          [
            "Closure"
          ],
          [
            "OC\\DB\\ConnectionAdapter"
          ]
        ]
      },
      {
        "file": "/var/www/html/apps/dav/lib/CardDAV/SyncService.php",
        "line": 124,
        "function": "createAddressBook",
        "class": "OCA\\DAV\\CardDAV\\CardDavBackend",
        "type": "->",
        "args": [
          "*** sensitive parameters replaced ***"
        ]
      },
      {
        "file": "/var/www/html/lib/public/AppFramework/Db/TTransactional.php",
        "line": 63,
        "function": "OCA\\DAV\\CardDAV\\{closure}",
        "class": "OCA\\DAV\\CardDAV\\SyncService",
        "type": "->",
        "args": [
          "*** sensitive parameters replaced ***"
        ]
      },
      {
        "file": "/var/www/html/apps/dav/lib/CardDAV/SyncService.php",
        "line": 127,
        "function": "atomic",
        "class": "OCA\\DAV\\CardDAV\\SyncService",
        "type": "->",
        "args": [
          [
            "Closure"
          ],
          [
            "OC\\DB\\ConnectionAdapter"
          ]
        ]
      },
      {
        "file": "/var/www/html/apps/dav/lib/CardDAV/SyncService.php",
        "line": 267,
        "function": "ensureSystemAddressBookExists",
        "class": "OCA\\DAV\\CardDAV\\SyncService",
        "type": "->",
        "args": [
          "*** sensitive parameters replaced ***",
          "*** sensitive parameters replaced ***",
          "*** sensitive parameters replaced ***"
        ]
      },
      {
        "file": "/var/www/html/apps/dav/lib/CardDAV/SyncService.php",
        "line": 223,
        "function": "getLocalSystemAddressBook",
        "class": "OCA\\DAV\\CardDAV\\SyncService",
        "type": "->",
        "args": []
      },
      {
        "file": "/var/www/html/apps/dav/lib/HookManager.php",
        "line": 108,
        "function": "updateUser",
        "class": "OCA\\DAV\\CardDAV\\SyncService",
        "type": "->",
        "args": [
          "*** sensitive parameters replaced ***"
        ]
      },
      {
        "file": "/var/www/html/lib/private/legacy/OC_Hook.php",
        "line": 105,
        "function": "postCreateUser",
        "class": "OCA\\DAV\\HookManager",
        "type": "->",
        "args": [
          [
            "*** sensitive parameters replaced ***",
            "*** sensitive parameters replaced ***"
          ]
        ]
      },
      {
        "file": "/var/www/html/lib/private/Server.php",
        "line": 550,
        "function": "emit",
        "class": "OC_Hook",
        "type": "::",
        "args": [
          "OC_User",
          "post_createUser",
          [
            "*** sensitive parameters replaced ***",
            "*** sensitive parameters replaced ***"
          ]
        ]
      },
      {
        "function": "OC\\{closure}",
        "class": "OC\\Server",
        "type": "->",
        "args": [
          "*** sensitive parameters replaced ***"
        ]
      },
      {
        "file": "/var/www/html/lib/private/Hooks/EmitterTrait.php",
        "line": 105,
        "function": "call_user_func_array",
        "args": [
          [
            "Closure"
          ],
          [
            "*** sensitive parameters replaced ***",
            "*** sensitive parameters replaced ***"
          ]
        ]
      },
      {
        "file": "/var/www/html/lib/private/Hooks/PublicEmitter.php",
        "line": 40,
        "function": "emit",
        "class": "OC\\Hooks\\BasicEmitter",
        "type": "->",
        "args": [
          "\\OC\\User",
          "postCreateUser",
          [
            "*** sensitive parameters replaced ***",
            "*** sensitive parameters replaced ***"
          ]
        ]
      },
      {
        "file": "/var/www/html/lib/private/User/Manager.php",
        "line": 472,
        "function": "emit",
        "class": "OC\\Hooks\\PublicEmitter",
        "type": "->",
        "args": [
          "\\OC\\User",
          "postCreateUser",
          [
            "*** sensitive parameters replaced ***",
            "*** sensitive parameters replaced ***"
          ]
        ]
      },
      {
        "file": "/var/www/html/lib/private/User/Manager.php",
        "line": 433,
        "function": "createUserFromBackend",
        "class": "OC\\User\\Manager",
        "type": "->",
        "args": [
          "*** sensitive parameters replaced ***"
        ]
      },
      {
        "file": "/var/www/html/core/Command/User/Add.php",
        "line": 114,
        "function": "createUser",
        "class": "OC\\User\\Manager",
        "type": "->",
        "args": [
          "*** sensitive parameters replaced ***"
        ]
      },
      {
        "file": "/var/www/html/3rdparty/symfony/console/Command/Command.php",
        "line": 298,
        "function": "execute",
        "class": "OC\\Core\\Command\\User\\Add",
        "type": "->",
        "args": [
          [
            "Symfony\\Component\\Console\\Input\\ArgvInput"
          ],
          [
            "Symfony\\Component\\Console\\Output\\ConsoleOutput"
          ]
        ]
      },
      {
        "file": "/var/www/html/3rdparty/symfony/console/Application.php",
        "line": 1040,
        "function": "run",
        "class": "Symfony\\Component\\Console\\Command\\Command",
        "type": "->",
        "args": [
          [
            "Symfony\\Component\\Console\\Input\\ArgvInput"
          ],
          [
            "Symfony\\Component\\Console\\Output\\ConsoleOutput"
          ]
        ]
      },
      {
        "file": "/var/www/html/3rdparty/symfony/console/Application.php",
        "line": 301,
        "function": "doRunCommand",
        "class": "Symfony\\Component\\Console\\Application",
        "type": "->",
        "args": [
          [
            "OC\\Core\\Command\\User\\Add"
          ],
          [
            "Symfony\\Component\\Console\\Input\\ArgvInput"
          ],
          [
            "Symfony\\Component\\Console\\Output\\ConsoleOutput"
          ]
        ]
      },
      {
        "file": "/var/www/html/3rdparty/symfony/console/Application.php",
        "line": 171,
        "function": "doRun",
        "class": "Symfony\\Component\\Console\\Application",
        "type": "->",
        "args": [
          [
            "Symfony\\Component\\Console\\Input\\ArgvInput"
          ],
          [
            "Symfony\\Component\\Console\\Output\\ConsoleOutput"
          ]
        ]
      },
      {
        "file": "/var/www/html/lib/private/Console/Application.php",
        "line": 206,
        "function": "run",
        "class": "Symfony\\Component\\Console\\Application",
        "type": "->",
        "args": [
          [
            "Symfony\\Component\\Console\\Input\\ArgvInput"
          ],
          [
            "Symfony\\Component\\Console\\Output\\ConsoleOutput"
          ]
        ]
      },
      {
        "file": "/var/www/html/console.php",
        "line": 100,
        "function": "run",
        "class": "OC\\Console\\Application",
        "type": "->",
        "args": []
      },
      {
        "file": "/var/www/html/occ",
        "line": 11,
        "args": [
          "/var/www/html/console.php"
        ],
        "function": "require_once"
      }
    ],
    "File": "/var/www/html/3rdparty/doctrine/dbal/src/Driver/API/MySQL/ExceptionConverter.php",
    "Line": 62,
    "Previous": {
      "Exception": "Doctrine\\DBAL\\Driver\\PDO\\Exception",
      "Message": "SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'principals/system/system-system' for key 'addressbook_index'",
      "Code": 1062,
      "Trace": [
        {
          "file": "/var/www/html/3rdparty/doctrine/dbal/src/Driver/PDO/Statement.php",
          "line": 132,
          "function": "new",
          "class": "Doctrine\\DBAL\\Driver\\PDO\\Exception",
          "type": "::",
          "args": [
            [
              "PDOException",
              [
                "23000",
                1062,
                "Duplicate entry 'principals/system/system-system' for key 'addressbook_index'"
              ]
            ]
          ]
        },
        {
          "file": "/var/www/html/3rdparty/doctrine/dbal/src/Connection.php",
          "line": 1202,
          "function": "execute",
          "class": "Doctrine\\DBAL\\Driver\\PDO\\Statement",
          "type": "->",
          "args": []
        },
        {
          "file": "/var/www/html/lib/private/DB/Connection.php",
          "line": 294,
          "function": "executeStatement",
          "class": "Doctrine\\DBAL\\Connection",
          "type": "->",
          "args": [
            "INSERT INTO `oc_addressbooks` (`uri`, `displayname`, `description`, `principaluri`, `synctoken`) VALUES(?, ?, ?, ?, ?)",
            [
              "*** sensitive parameters replaced ***",
              "*** sensitive parameters replaced ***",
              "System addressbook which holds all users of this instance",
              "*** sensitive parameters replaced ***",
              1
            ],
            []
          ]
        },
        {
          "file": "/var/www/html/3rdparty/doctrine/dbal/src/Query/QueryBuilder.php",
          "line": 386,
          "function": "executeStatement",
          "class": "OC\\DB\\Connection",
          "type": "->",
          "args": [
            "INSERT INTO `oc_addressbooks` (`uri`, `displayname`, `description`, `principaluri`, `synctoken`) VALUES(:uri, :displayname, :description, :principaluri, :synctoken)",
            [
              "*** sensitive parameters replaced ***",
              "System addressbook which holds all users of this instance",
              "*** sensitive parameters replaced ***",
              "*** sensitive parameters replaced ***",
              1
            ],
            []
          ]
        },
        {
          "file": "/var/www/html/lib/private/DB/QueryBuilder/QueryBuilder.php",
          "line": 280,
          "function": "execute",
          "class": "Doctrine\\DBAL\\Query\\QueryBuilder",
          "type": "->",
          "args": []
        },
        {
          "file": "/var/www/html/apps/dav/lib/CardDAV/CardDavBackend.php",
          "line": 436,
          "function": "execute",
          "class": "OC\\DB\\QueryBuilder\\QueryBuilder",
          "type": "->",
          "args": []
        },
        {
          "file": "/var/www/html/lib/public/AppFramework/Db/TTransactional.php",
          "line": 63,
          "function": "OCA\\DAV\\CardDAV\\{closure}",
          "class": "OCA\\DAV\\CardDAV\\CardDavBackend",
          "type": "->",
          "args": [
            "*** sensitive parameters replaced ***"
          ]
        },
        {
          "file": "/var/www/html/apps/dav/lib/CardDAV/CardDavBackend.php",
          "line": 443,
          "function": "atomic",
          "class": "OCA\\DAV\\CardDAV\\CardDavBackend",
          "type": "->",
          "args": [
            [
              "Closure"
            ],
            [
              "OC\\DB\\ConnectionAdapter"
            ]
          ]
        },
        {
          "file": "/var/www/html/apps/dav/lib/CardDAV/SyncService.php",
          "line": 124,
          "function": "createAddressBook",
          "class": "OCA\\DAV\\CardDAV\\CardDavBackend",
          "type": "->",
          "args": [
            "*** sensitive parameters replaced ***"
          ]
        },
        {
          "file": "/var/www/html/lib/public/AppFramework/Db/TTransactional.php",
          "line": 63,
          "function": "OCA\\DAV\\CardDAV\\{closure}",
          "class": "OCA\\DAV\\CardDAV\\SyncService",
          "type": "->",
          "args": [
            "*** sensitive parameters replaced ***"
          ]
        },
        {
          "file": "/var/www/html/apps/dav/lib/CardDAV/SyncService.php",
          "line": 127,
          "function": "atomic",
          "class": "OCA\\DAV\\CardDAV\\SyncService",
          "type": "->",
          "args": [
            [
              "Closure"
            ],
            [
              "OC\\DB\\ConnectionAdapter"
            ]
          ]
        },
        {
          "file": "/var/www/html/apps/dav/lib/CardDAV/SyncService.php",
          "line": 267,
          "function": "ensureSystemAddressBookExists",
          "class": "OCA\\DAV\\CardDAV\\SyncService",
          "type": "->",
          "args": [
            "*** sensitive parameters replaced ***",
            "*** sensitive parameters replaced ***",
            "*** sensitive parameters replaced ***"
          ]
        },
        {
          "file": "/var/www/html/apps/dav/lib/CardDAV/SyncService.php",
          "line": 223,
          "function": "getLocalSystemAddressBook",
          "class": "OCA\\DAV\\CardDAV\\SyncService",
          "type": "->",
          "args": []
        },
        {
          "file": "/var/www/html/apps/dav/lib/HookManager.php",
          "line": 108,
          "function": "updateUser",
          "class": "OCA\\DAV\\CardDAV\\SyncService",
          "type": "->",
          "args": [
            "*** sensitive parameters replaced ***"
          ]
        },
        {
          "file": "/var/www/html/lib/private/legacy/OC_Hook.php",
          "line": 105,
          "function": "postCreateUser",
          "class": "OCA\\DAV\\HookManager",
          "type": "->",
          "args": [
            [
              "*** sensitive parameters replaced ***",
              "*** sensitive parameters replaced ***"
            ]
          ]
        },
        {
          "file": "/var/www/html/lib/private/Server.php",
          "line": 550,
          "function": "emit",
          "class": "OC_Hook",
          "type": "::",
          "args": [
            "OC_User",
            "post_createUser",
            [
              "*** sensitive parameters replaced ***",
              "*** sensitive parameters replaced ***"
            ]
          ]
        },
        {
          "function": "OC\\{closure}",
          "class": "OC\\Server",
          "type": "->",
          "args": [
            "*** sensitive parameters replaced ***"
          ]
        },
        {
          "file": "/var/www/html/lib/private/Hooks/EmitterTrait.php",
          "line": 105,
          "function": "call_user_func_array",
          "args": [
            [
              "Closure"
            ],
            [
              "*** sensitive parameters replaced ***",
              "*** sensitive parameters replaced ***"
            ]
          ]
        },
        {
          "file": "/var/www/html/lib/private/Hooks/PublicEmitter.php",
          "line": 40,
          "function": "emit",
          "class": "OC\\Hooks\\BasicEmitter",
          "type": "->",
          "args": [
            "\\OC\\User",
            "postCreateUser",
            [
              "*** sensitive parameters replaced ***",
              "*** sensitive parameters replaced ***"
            ]
          ]
        },
        {
          "file": "/var/www/html/lib/private/User/Manager.php",
          "line": 472,
          "function": "emit",
          "class": "OC\\Hooks\\PublicEmitter",
          "type": "->",
          "args": [
            "\\OC\\User",
            "postCreateUser",
            [
              "*** sensitive parameters replaced ***",
              "*** sensitive parameters replaced ***"
            ]
          ]
        },
        {
          "file": "/var/www/html/lib/private/User/Manager.php",
          "line": 433,
          "function": "createUserFromBackend",
          "class": "OC\\User\\Manager",
          "type": "->",
          "args": [
            "*** sensitive parameters replaced ***"
          ]
        },
        {
          "file": "/var/www/html/core/Command/User/Add.php",
          "line": 114,
          "function": "createUser",
          "class": "OC\\User\\Manager",
          "type": "->",
          "args": [
            "*** sensitive parameters replaced ***"
          ]
        },
        {
          "file": "/var/www/html/3rdparty/symfony/console/Command/Command.php",
          "line": 298,
          "function": "execute",
          "class": "OC\\Core\\Command\\User\\Add",
          "type": "->",
          "args": [
            [
              "Symfony\\Component\\Console\\Input\\ArgvInput"
            ],
            [
              "Symfony\\Component\\Console\\Output\\ConsoleOutput"
            ]
          ]
        },
        {
          "file": "/var/www/html/3rdparty/symfony/console/Application.php",
          "line": 1040,
          "function": "run",
          "class": "Symfony\\Component\\Console\\Command\\Command",
          "type": "->",
          "args": [
            [
              "Symfony\\Component\\Console\\Input\\ArgvInput"
            ],
            [
              "Symfony\\Component\\Console\\Output\\ConsoleOutput"
            ]
          ]
        },
        {
          "file": "/var/www/html/3rdparty/symfony/console/Application.php",
          "line": 301,
          "function": "doRunCommand",
          "class": "Symfony\\Component\\Console\\Application",
          "type": "->",
          "args": [
            [
              "OC\\Core\\Command\\User\\Add"
            ],
            [
              "Symfony\\Component\\Console\\Input\\ArgvInput"
            ],
            [
              "Symfony\\Component\\Console\\Output\\ConsoleOutput"
            ]
          ]
        },
        {
          "file": "/var/www/html/3rdparty/symfony/console/Application.php",
          "line": 171,
          "function": "doRun",
          "class": "Symfony\\Component\\Console\\Application",
          "type": "->",
          "args": [
            [
              "Symfony\\Component\\Console\\Input\\ArgvInput"
            ],
            [
              "Symfony\\Component\\Console\\Output\\ConsoleOutput"
            ]
          ]
        },
        {
          "file": "/var/www/html/lib/private/Console/Application.php",
          "line": 206,
          "function": "run",
          "class": "Symfony\\Component\\Console\\Application",
          "type": "->",
          "args": [
            [
              "Symfony\\Component\\Console\\Input\\ArgvInput"
            ],
            [
              "Symfony\\Component\\Console\\Output\\ConsoleOutput"
            ]
          ]
        },
        {
          "file": "/var/www/html/console.php",
          "line": 100,
          "function": "run",
          "class": "OC\\Console\\Application",
          "type": "->",
          "args": []
        },
        {
          "file": "/var/www/html/occ",
          "line": 11,
          "args": [
            "/var/www/html/console.php"
          ],
          "function": "require_once"
        }
      ],
      "File": "/var/www/html/3rdparty/doctrine/dbal/src/Driver/PDO/Exception.php",
      "Line": 28,
      "Previous": {
        "Exception": "PDOException",
        "Message": "SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'principals/system/system-system' for key 'addressbook_index'",
        "Code": "23000",
        "Trace": [
          {
            "file": "/var/www/html/3rdparty/doctrine/dbal/src/Driver/PDO/Statement.php",
            "line": 130,
            "function": "execute",
            "class": "PDOStatement",
            "type": "->",
            "args": [
              null
            ]
          },
          {
            "file": "/var/www/html/3rdparty/doctrine/dbal/src/Connection.php",
            "line": 1202,
            "function": "execute",
            "class": "Doctrine\\DBAL\\Driver\\PDO\\Statement",
            "type": "->",
            "args": []
          },
          {
            "file": "/var/www/html/lib/private/DB/Connection.php",
            "line": 294,
            "function": "executeStatement",
            "class": "Doctrine\\DBAL\\Connection",
            "type": "->",
            "args": [
              "INSERT INTO `oc_addressbooks` (`uri`, `displayname`, `description`, `principaluri`, `synctoken`) VALUES(?, ?, ?, ?, ?)",
              [
                "*** sensitive parameters replaced ***",
                "*** sensitive parameters replaced ***",
                "System addressbook which holds all users of this instance",
                "*** sensitive parameters replaced ***",
                1
              ],
              []
            ]
          },
          {
            "file": "/var/www/html/3rdparty/doctrine/dbal/src/Query/QueryBuilder.php",
            "line": 386,
            "function": "executeStatement",
            "class": "OC\\DB\\Connection",
            "type": "->",
            "args": [
              "INSERT INTO `oc_addressbooks` (`uri`, `displayname`, `description`, `principaluri`, `synctoken`) VALUES(:uri, :displayname, :description, :principaluri, :synctoken)",
              [
                "*** sensitive parameters replaced ***",
                "System addressbook which holds all users of this instance",
                "*** sensitive parameters replaced ***",
                "*** sensitive parameters replaced ***",
                1
              ],
              []
            ]
          },
          {
            "file": "/var/www/html/lib/private/DB/QueryBuilder/QueryBuilder.php",
            "line": 280,
            "function": "execute",
            "class": "Doctrine\\DBAL\\Query\\QueryBuilder",
            "type": "->",
            "args": []
          },
          {
            "file": "/var/www/html/apps/dav/lib/CardDAV/CardDavBackend.php",
            "line": 436,
            "function": "execute",
            "class": "OC\\DB\\QueryBuilder\\QueryBuilder",
            "type": "->",
            "args": []
          },
          {
            "file": "/var/www/html/lib/public/AppFramework/Db/TTransactional.php",
            "line": 63,
            "function": "OCA\\DAV\\CardDAV\\{closure}",
            "class": "OCA\\DAV\\CardDAV\\CardDavBackend",
            "type": "->",
            "args": [
              "*** sensitive parameters replaced ***"
            ]
          },
          {
            "file": "/var/www/html/apps/dav/lib/CardDAV/CardDavBackend.php",
            "line": 443,
            "function": "atomic",
            "class": "OCA\\DAV\\CardDAV\\CardDavBackend",
            "type": "->",
            "args": [
              [
                "Closure"
              ],
              [
                "OC\\DB\\ConnectionAdapter"
              ]
            ]
          },
          {
            "file": "/var/www/html/apps/dav/lib/CardDAV/SyncService.php",
            "line": 124,
            "function": "createAddressBook",
            "class": "OCA\\DAV\\CardDAV\\CardDavBackend",
            "type": "->",
            "args": [
              "*** sensitive parameters replaced ***"
            ]
          },
          {
            "file": "/var/www/html/lib/public/AppFramework/Db/TTransactional.php",
            "line": 63,
            "function": "OCA\\DAV\\CardDAV\\{closure}",
            "class": "OCA\\DAV\\CardDAV\\SyncService",
            "type": "->",
            "args": [
              "*** sensitive parameters replaced ***"
            ]
          },
          {
            "file": "/var/www/html/apps/dav/lib/CardDAV/SyncService.php",
            "line": 127,
            "function": "atomic",
            "class": "OCA\\DAV\\CardDAV\\SyncService",
            "type": "->",
            "args": [
              [
                "Closure"
              ],
              [
                "OC\\DB\\ConnectionAdapter"
              ]
            ]
          },
          {
            "file": "/var/www/html/apps/dav/lib/CardDAV/SyncService.php",
            "line": 267,
            "function": "ensureSystemAddressBookExists",
            "class": "OCA\\DAV\\CardDAV\\SyncService",
            "type": "->",
            "args": [
              "*** sensitive parameters replaced ***",
              "*** sensitive parameters replaced ***",
              "*** sensitive parameters replaced ***"
            ]
          },
          {
            "file": "/var/www/html/apps/dav/lib/CardDAV/SyncService.php",
            "line": 223,
            "function": "getLocalSystemAddressBook",
            "class": "OCA\\DAV\\CardDAV\\SyncService",
            "type": "->",
            "args": []
          },
          {
            "file": "/var/www/html/apps/dav/lib/HookManager.php",
            "line": 108,
            "function": "updateUser",
            "class": "OCA\\DAV\\CardDAV\\SyncService",
            "type": "->",
            "args": [
              "*** sensitive parameters replaced ***"
            ]
          },
          {
            "file": "/var/www/html/lib/private/legacy/OC_Hook.php",
            "line": 105,
            "function": "postCreateUser",
            "class": "OCA\\DAV\\HookManager",
            "type": "->",
            "args": [
              [
                "*** sensitive parameters replaced ***",
                "*** sensitive parameters replaced ***"
              ]
            ]
          },
          {
            "file": "/var/www/html/lib/private/Server.php",
            "line": 550,
            "function": "emit",
            "class": "OC_Hook",
            "type": "::",
            "args": [
              "OC_User",
              "post_createUser",
              [
                "*** sensitive parameters replaced ***",
                "*** sensitive parameters replaced ***"
              ]
            ]
          },
          {
            "function": "OC\\{closure}",
            "class": "OC\\Server",
            "type": "->",
            "args": [
              "*** sensitive parameters replaced ***"
            ]
          },
          {
            "file": "/var/www/html/lib/private/Hooks/EmitterTrait.php",
            "line": 105,
            "function": "call_user_func_array",
            "args": [
              [
                "Closure"
              ],
              [
                "*** sensitive parameters replaced ***",
                "*** sensitive parameters replaced ***"
              ]
            ]
          },
          {
            "file": "/var/www/html/lib/private/Hooks/PublicEmitter.php",
            "line": 40,
            "function": "emit",
            "class": "OC\\Hooks\\BasicEmitter",
            "type": "->",
            "args": [
              "\\OC\\User",
              "postCreateUser",
              [
                "*** sensitive parameters replaced ***",
                "*** sensitive parameters replaced ***"
              ]
            ]
          },
          {
            "file": "/var/www/html/lib/private/User/Manager.php",
            "line": 472,
            "function": "emit",
            "class": "OC\\Hooks\\PublicEmitter",
            "type": "->",
            "args": [
              "\\OC\\User",
              "postCreateUser",
              [
                "*** sensitive parameters replaced ***",
                "*** sensitive parameters replaced ***"
              ]
            ]
          },
          {
            "file": "/var/www/html/lib/private/User/Manager.php",
            "line": 433,
            "function": "createUserFromBackend",
            "class": "OC\\User\\Manager",
            "type": "->",
            "args": [
              "*** sensitive parameters replaced ***"
            ]
          },
          {
            "file": "/var/www/html/core/Command/User/Add.php",
            "line": 114,
            "function": "createUser",
            "class": "OC\\User\\Manager",
            "type": "->",
            "args": [
              "*** sensitive parameters replaced ***"
            ]
          },
          {
            "file": "/var/www/html/3rdparty/symfony/console/Command/Command.php",
            "line": 298,
            "function": "execute",
            "class": "OC\\Core\\Command\\User\\Add",
            "type": "->",
            "args": [
              [
                "Symfony\\Component\\Console\\Input\\ArgvInput"
              ],
              [
                "Symfony\\Component\\Console\\Output\\ConsoleOutput"
              ]
            ]
          },
          {
            "file": "/var/www/html/3rdparty/symfony/console/Application.php",
            "line": 1040,
            "function": "run",
            "class": "Symfony\\Component\\Console\\Command\\Command",
            "type": "->",
            "args": [
              [
                "Symfony\\Component\\Console\\Input\\ArgvInput"
              ],
              [
                "Symfony\\Component\\Console\\Output\\ConsoleOutput"
              ]
            ]
          },
          {
            "file": "/var/www/html/3rdparty/symfony/console/Application.php",
            "line": 301,
            "function": "doRunCommand",
            "class": "Symfony\\Component\\Console\\Application",
            "type": "->",
            "args": [
              [
                "OC\\Core\\Command\\User\\Add"
              ],
              [
                "Symfony\\Component\\Console\\Input\\ArgvInput"
              ],
              [
                "Symfony\\Component\\Console\\Output\\ConsoleOutput"
              ]
            ]
          },
          {
            "file": "/var/www/html/3rdparty/symfony/console/Application.php",
            "line": 171,
            "function": "doRun",
            "class": "Symfony\\Component\\Console\\Application",
            "type": "->",
            "args": [
              [
                "Symfony\\Component\\Console\\Input\\ArgvInput"
              ],
              [
                "Symfony\\Component\\Console\\Output\\ConsoleOutput"
              ]
            ]
          },
          {
            "file": "/var/www/html/lib/private/Console/Application.php",
            "line": 206,
            "function": "run",
            "class": "Symfony\\Component\\Console\\Application",
            "type": "->",
            "args": [
              [
                "Symfony\\Component\\Console\\Input\\ArgvInput"
              ],
              [
                "Symfony\\Component\\Console\\Output\\ConsoleOutput"
              ]
            ]
          },
          {
            "file": "/var/www/html/console.php",
            "line": 100,
            "function": "run",
            "class": "OC\\Console\\Application",
            "type": "->",
            "args": []
          },
          {
            "file": "/var/www/html/occ",
            "line": 11,
            "args": [
              "/var/www/html/console.php"
            ],
            "function": "require_once"
          }
        ],
        "File": "/var/www/html/3rdparty/doctrine/dbal/src/Driver/PDO/Statement.php",
        "Line": 130
      }
    },
    "CustomMessage": "Exception thrown: Doctrine\\DBAL\\Exception\\UniqueConstraintViolationException"
  }
}
@juliusknorr juliusknorr added the bug label Dec 4, 2023
@ChristophWurst
Copy link
Member

The transaction in \OCA\DAV\CardDAV\SyncService::ensureSystemAddressBookExists should guard the system from this problem if transaction level is READ COMMITTED. But I see that the trace shows a second atomic operation on a deeper level. I wonder if that is problematic.

@ChristophWurst ChristophWurst added 1. to develop Accepted and waiting to be taken care of feature: dav feature: carddav Related to CardDAV internals labels Dec 4, 2023
@ChristophWurst
Copy link
Member

"class": "Doctrine\DBAL\Connections\PrimaryReadReplicaConnection"

👀

@juliusknorr
Copy link
Member Author

Whoops, good catch. Apparently had a different local branch checked out, let me see if that is actually related

@juliusknorr
Copy link
Member Author

Also happens on plain master, updated the trace above

@kesselb
Copy link
Contributor

kesselb commented Dec 4, 2023

call multiple occ user:add in parallel

As workaround, you could try to run dav:sync-system-addressbook before user:add to create the system addressbook upfront.

@juliusknorr
Copy link
Member Author

Yep, that works

@ChristophWurst
Copy link
Member

My attempt: #42052

Maybe I'm overengineering this but it's hard to make the db operations work under all conditions

@kesselb
Copy link
Contributor

kesselb commented Dec 6, 2023

Hmm, what about a migration to create the sab when installing Nextcloud?

@ChristophWurst
Copy link
Member

ChristophWurst commented Dec 7, 2023

Maybe I'm overengineering

Yes. #42102 is the fix.

Only fixes a read after write, not the insert conflict. Over engineering it is.

@ChristophWurst ChristophWurst added 3. to review Waiting for reviews and removed 1. to develop Accepted and waiting to be taken care of labels Sep 17, 2024
@ChristophWurst ChristophWurst self-assigned this Sep 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3. to review Waiting for reviews 29-feedback bug feature: carddav Related to CardDAV internals feature: dav
Projects
Status: ☑️ Done
Development

Successfully merging a pull request may close this issue.

4 participants