laravel / telescope

An elegant debug assistant for the Laravel framework.

Home Page:https://laravel.com/docs/telescope

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Telescope Entries Key Collisions Across Multiple Servers

GavG opened this issue · comments

commented

Telescope Version

4.17.4

Laravel Version

10.42.0

PHP Version

8.2

Database Driver & Version

MySQL 8.0.0 InnoDB

Description

When running Telescope across multiple servers we occasionally see duplicate key exceptions on the entries, example:

SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '9b3441f8-afb8-49d2-b8f8-e6bd7403708a-App\Models\ConnectorConfig' for key 'telescope_entries_tags.PRIMARY' (Connection: mysql, SQL: insert into telescope_entries_tags (entry_uuid, tag) values (9b3441f8-afb8-49d2-b8f8-e6bd7403708a, App\Models\ConnectorConfig))

On inspection, these have all been for recorded select queries which are happening at the same time. I was unable to find anything in the docs regarding mitigating this.

I expect the issue is time-based UUIDs. One possible fix would be to switch to a UUID generator that uses the server's identity, or one could add a column to the entries table to record the server ID and add this to the key.

Perhaps there are other viable solutions I haven't thought of, feel free to suggest them. In any case, I expect this doesn't affect a lot of users as our use case is quite niche, so it may not be worth solving in code (this could cause backwards compatibility issues), but perhaps worth mentioning in the documentation along with suggestions for mitigation.

Steps To Reproduce

Spin up 2 or more servers running Telescope performing the same selects on a sub-miute schedule, and observe that key collisions start to occur every so often.

Could you give us the full stack trace please?

commented

@driesvints Sure:

{
    "class": "Illuminate\\Database\\UniqueConstraintViolationException",
    "message": "SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '9b3441f8-afb8-49d2-b8f8-e6bd7403708a-App\\Models\\ConnectorConfig' for key 'telescope_entries_tags.PRIMARY' (Connection: mysql, SQL: insert into `telescope_entries_tags` (`entry_uuid`, `tag`) values (9b3441f8-afb8-49d2-b8f8-e6bd7403708a, App\\Models\\ConnectorConfig))",
    "code": 23000,
    "file": "/app/vendor/laravel/framework/src/Illuminate/Database/Connection.php:817",
    "trace": [
        "/app/vendor/laravel/framework/src/Illuminate/Database/Connection.php:976",
        "/app/vendor/laravel/framework/src/Illuminate/Database/Connection.php:955",
        "/app/vendor/laravel/framework/src/Illuminate/Database/Connection.php:778",
        "/app/vendor/laravel/framework/src/Illuminate/Database/Connection.php:569",
        "/app/vendor/laravel/framework/src/Illuminate/Database/Connection.php:533",
        "/app/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php:3336",
        "/app/vendor/laravel/telescope/src/Storage/DatabaseEntriesRepository.php:192",
        "/app/vendor/laravel/framework/src/Illuminate/Collections/Traits/EnumeratesValues.php:240",
        "/app/vendor/laravel/telescope/src/Storage/DatabaseEntriesRepository.php:191",
        "/app/vendor/laravel/telescope/src/Storage/DatabaseEntriesRepository.php:151",
        "/app/vendor/laravel/telescope/src/Telescope.php:668",
        "/app/vendor/laravel/telescope/src/Telescope.php:293",
        "/app/vendor/laravel/telescope/src/Telescope.php:660",
        "/app/vendor/laravel/telescope/src/ListensForStorageOpportunities.php:65",
        "/app/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:36",
        "/app/vendor/laravel/framework/src/Illuminate/Container/Util.php:41",
        "/app/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:81",
        "/app/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:35",
        "/app/vendor/laravel/framework/src/Illuminate/Container/Container.php:662",
        "/app/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:1274",
        "/app/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php:220",
        "/app/artisan:51"
    ],
    "previous": {
        "class": "PDOException",
        "message": "SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '9b3441f8-afb8-49d2-b8f8-e6bd7403708a-App\\Models\\ConnectorConfig' for key 'telescope_entries_tags.PRIMARY'",
        "code": 23000,
        "file": "/app/vendor/laravel/framework/src/Illuminate/Database/Connection.php:580",
        "trace": [
            "/app/vendor/laravel/framework/src/Illuminate/Database/Connection.php:580",
            "/app/vendor/laravel/framework/src/Illuminate/Database/Connection.php:809",
            "/app/vendor/laravel/framework/src/Illuminate/Database/Connection.php:976",
            "/app/vendor/laravel/framework/src/Illuminate/Database/Connection.php:955",
            "/app/vendor/laravel/framework/src/Illuminate/Database/Connection.php:778",
            "/app/vendor/laravel/framework/src/Illuminate/Database/Connection.php:569",
            "/app/vendor/laravel/framework/src/Illuminate/Database/Connection.php:533",
            "/app/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php:3336",
            "/app/vendor/laravel/telescope/src/Storage/DatabaseEntriesRepository.php:192",
            "/app/vendor/laravel/framework/src/Illuminate/Collections/Traits/EnumeratesValues.php:240",
            "/app/vendor/laravel/telescope/src/Storage/DatabaseEntriesRepository.php:191",
            "/app/vendor/laravel/telescope/src/Storage/DatabaseEntriesRepository.php:151",
            "/app/vendor/laravel/telescope/src/Telescope.php:668",
            "/app/vendor/laravel/telescope/src/Telescope.php:293",
            "/app/vendor/laravel/telescope/src/Telescope.php:660",
            "/app/vendor/laravel/telescope/src/ListensForStorageOpportunities.php:65",
            "/app/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:36",
            "/app/vendor/laravel/framework/src/Illuminate/Container/Util.php:41",
            "/app/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:81",
            "/app/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:35",
            "/app/vendor/laravel/framework/src/Illuminate/Container/Container.php:662",
            "/app/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:1274",
            "/app/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php:220",
            "/app/artisan:51"
        ]
    }
}

Heya, thanks for that. I sent in a PR for this: #1431

commented

Brill 👍