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

Telescope Entries Key Collisions Across Multiple Servers #1430

Closed
GavG opened this issue Jan 29, 2024 · 4 comments · Fixed by #1431
Closed

Telescope Entries Key Collisions Across Multiple Servers #1430

GavG opened this issue Jan 29, 2024 · 4 comments · Fixed by #1431
Labels

Comments

@GavG
Copy link

GavG commented Jan 29, 2024

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.

@driesvints
Copy link
Member

Could you give us the full stack trace please?

@GavG
Copy link
Author

GavG commented Jan 30, 2024

@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"
        ]
    }
}

@driesvints
Copy link
Member

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

@GavG
Copy link
Author

GavG commented Jan 30, 2024

Brill 👍

@GavG GavG closed this as completed Jan 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants