Skip to content
GitLab Next
  • Menu
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • GitLab FOSS GitLab FOSS
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 0
    • Issues 0
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
    • Requirements
  • Merge requests 1
    • Merge requests 1
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages & Registries
    • Packages & Registries
    • Package Registry
    • Container Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Metrics
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • Code review
    • Insights
    • Issue
    • Repository
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Commits
  • Issue Boards
Collapse sidebar
  • GitLab.org
  • GitLab FOSSGitLab FOSS
  • Issues
  • #31114
Closed
Open
Created Apr 18, 2017 by Yorick Peterse@yorickpeterseContributor

Internal IDs are not atomic

The code for generating internal IDs (iids) is as follows:

def set_iid
  if iid.blank?
    records = project.send(self.class.name.tableize)
    records = records.with_deleted if self.paranoid?
    max_iid = records.maximum(:iid)
                                                     
    self.iid = max_iid.to_i + 1
  end
end

This code is not atomic, meaning it's possible for 2 issues trying to use the same iid. This will lead to a unique constraint failure, resulting in errors showing up to a user. We're seeing this in our PostgreSQL logs in the form of:

ERROR: duplicate key value violations
  - unique constraint "index_issues_on_project_id_and_iid"

This method should be made atomic somehow, or the issue creation process should retry in case of unique constraints.

Assignee
Assign to
Time tracking