Red Hat Satellite engineering is moving the tracking of its product development work on Satellite to Red Hat Jira ( If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "Satellite project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs will be migrated starting at the end of May. If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "Satellite project" in Red Hat Jira (issue links are of type "", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
Bug 1612909 - Concurrent creation of subnets can lead to records with duplicate names
Summary: Concurrent creation of subnets can lead to records with duplicate names
Alias: None
Product: Red Hat Satellite
Classification: Red Hat
Component: Networking
Version: 6.3.2
Hardware: Unspecified
OS: Unspecified
Target Milestone: 6.4.0
Assignee: Ivan Necas
QA Contact: Jitendra Yejare
Depends On:
TreeView+ depends on / blocked
Reported: 2018-08-06 13:59 UTC by Ivan Necas
Modified: 2021-12-10 16:53 UTC (History)
7 users (show)

Fixed In Version: foreman-
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Last Closed: 2018-10-16 19:02:08 UTC
Target Upstream Version:

Attachments (Terms of Use)

System ID Private Priority Status Summary Last Updated
Foreman Issue Tracker 24546 0 None None None 2018-08-06 14:42:34 UTC

Description Ivan Necas 2018-08-06 13:59:43 UTC
Description of problem:
Concurrent creation of subnets can lead to records with duplicate names

Version-Release number of selected component (if applicable):
Verified in 6.3, as well as in upstream, has been around probably from the beginning

How reproducible:
Under concurrent requets

for x in {1..20}; do
   echo "Attempt $x"
   for y in {1..4}; do
     curl -k -u admin:changeme -X POST -d '{"name":"subnet-'$x'","network":"","mask":""}' -H 'Content-Type: application/json' http://localhost:300/api/v2/subnets & 
   sleep 1

Actual results:
    select name, count(*) from subnets group by name having count(*) > 1;

returns multiple records

Expected results:

    select name, count(*) from subnets group by name having count(*) > 1;

returns no record.

Additional info:

Testing notes: when verifying, please first generate multiple subnets with an installation without this fix and try to migrate to the version with it.

Comment 1 Ivan Necas 2018-08-06 14:42:33 UTC
Created redmine issue from this bug

Comment 2 Ivan Necas 2018-08-06 14:55:42 UTC
Here is the cleanup script to merge the duplicate subnet records:

cat <<EOF | foreman-rake console
  duplicate_names ='count(name) > 1').pluck(:name)"Found #{duplicate_names} duplicate subnet names.")
  duplicate_names.each do |name|
    winner, *loosers = Subnet.unscoped.where(name: name)"Merging duplicate subnets with name '#{name}', " \
                      "keeping #{}, merging with #{}")
    Hostgroup.unscoped.where(:subnet_id => =>
    Nic::Base.unscoped.where(:subnet_id => =>
    SubnetParameter.unscoped.where(:reference_id => =>

Comment 4 Satellite Program 2018-08-06 16:02:40 UTC
Upstream bug assigned to inecas

Comment 5 Satellite Program 2018-08-06 16:02:43 UTC
Upstream bug assigned to inecas

Comment 8 Satellite Program 2018-09-05 18:01:51 UTC
Moving this bug to POST for triage into Satellite 6 since the upstream issue has been resolved.

Comment 10 Jitendra Yejare 2018-09-11 10:08:09 UTC

@ Satellite 6.4 snap 21


1. Run API command to create concurrent subnets with same name(using the same script mentioned in Description of this bug)


1. The concurrent subnets are created but not duplicates.
2. An error is returned on attempting to create duplicate subnet as:
"error": {"id":null,"errors":{"name":["has already been taken"]},"full_messages":["Name has already been taken"]}

Hence the bug is now verified.

Also, I observed sometimes the incorrect/db error is redirected while cresting duplicate subnets concurrently as:
"error": {"message":"PG::UniqueViolation: ERROR:  duplicate key value violates unique constraint \"index_subnets_on_name\"\nDETAIL:  Key (name)=(bug_subnet-19) already exists.\n: INSERT INTO \"subnets\" (\"network\", \"mask\", \"name\", \"created_at\", \"updated_at\") VALUES ($1, $2, $3, $4, $5) RETURNING \"id\""}

I would raise another bz for same.

Comment 13 Bryan Kearney 2018-10-16 19:02:08 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

Note You need to log in before you can comment on or make changes to this bug.