Verified Solution

[gitlab-org/gitlab] 18.8: table_sync_function causes PG::UniqueViolation on git-upload-pack, breaking all CI pipelines after first run per day

Sponsored Content
### ROOT CAUSE The issue arises from a PostgreSQL trigger `table_sync_function_c237afdf68` introduced by a 18.8 batched background migration. This trigger causes a `PG::UniqueViolation` when called multiple times during the `git-upload-pack` operation, specifically on the second and subsequent calls per day. The trigger likely attempts to insert or update records that violate a unique constraint, possibly due to a one-time setup or migration that leaves the database in a state where duplicate operations occur. The first successful pipeline might be initializing the necessary state, but subsequent calls trigger the violation. ### CODE FIX To resolve the issue, modify the trigger function to handle unique constraint violations gracefully. Specifically, change the function to use `ON CONFLICT DO NOTHING` (if using PostgreSQL) to skip duplicate key errors. Here's the fix: ```sql -- Find the function definition (likely in the migration or schema) -- Replace the existing function with the following: CREATE OR REPLACE FUNCTION table_sync_function_c237afdf68() RETURNS TRIGGER AS $$ BEGIN -- Use ON CONFLICT DO NOTHING to avoid unique violation INSERT INTO your_table_name (unique_column, other_columns) VALUES (value1, value2) ON CONFLICT (unique_column) DO NOTHING; -- ... rest of the function code ... RETURN NEW; END; $$ LANGUAGE plpgsql; ``` Additionally, ensure the migration is idempotent or run only once per day if applicable. If the migration itself is causing the issue, revert or modify the migration to prevent duplicate execution. Apply this fix via a patch or update to the relevant migration file in the GitLab repository.
Deploy on DigitalOcean ($200 Credit)

Related Fixes

Race condition in thread pool
[facebook/react] [Compiler Bug]: constant gets memoized with a wrong dependency
[microsoft/vscode] Command run MCP is buggy