Bug #24732
closedFIPS Scheduled synchronization task ends with PG::UniqueViolation: ERROR: duplicate key value violates unique constraint "index_katello_repository_rpms_on_rpm_id_and_repository_id"
Description
Testing on CentOS with FIPS environment enabled using katello-3.9.0-5.el7.noarch,
when a repo synchronization is triggered by a recurring syncplan, the first run fails with the following exception:
```
ActiveRecord::RecordNotUnique: PG::UniqueViolation: ERROR: duplicate key value violates unique constraint "index_katello_repository_rpms_on_rpm_id_and_repository_id"
DETAIL: Key (rpm_id, repository_id)=(1, 541) already exists.
: INSERT INTO katello_repository_rpms (rpm_id, repository_id, created_at, updated_at) VALUES (1, 541, '2018-08-23 14:22:04', '2018-08-23 14:22:04'), (2, 541, '2018-08-23 14:22:04', '2018-08-23 14:22:04'), (3, 541, '2018-08-23 14:22:04', '2018-08-23 14:22:04'), (4, 541, '2018-08-23 14:22:04', '2018-08-23 14:22:04'), (5, 541, '2018-08-23 14:22:04', '2018-08-23 14:22:04'), (6, 541, '2018-08-23 14:22:04', '2018-08-23 14:22:04'), (7, 541, '2018-08-23 14:22:04', '2018-08-23 14:22:04'), (8, 541, '2018-08-23 14:22:04', '2018-08-23 14:22:04'), (9, 541, '2018-08-23 14:22:04', '2018-08-23 14:22:04'), (10, 541, '2018-08-23 14:22:04', '2018-08-23 14:22:04'), (11, 541, '2018-08-23 14:22:04', '2018-08-23 14:22:04'), (12, 541, '2018-08-23 14:22:04', '2018-08-23 14:22:04'), (13, 541, '2018-08-23 14:22:04', '2018-08-23 14:22:04'), (14, 541, '2018-08-23 14:22:04', '2018-08-23 14:22:04'), (15, 541, '2018-08-23 14:22:04', '2018-08-23 14:22:04'), (16, 541, '2018-08-23 14:22:04', '2018-08-23 14:22:04'), (17, 541, '2018-08-23 14:22:04', '2018-08-23 14:22:04'), (18, 541, '2018-08-23 14:22:04', '2018-08-23 14:22:04'), (19, 541, '2018-08-23 14:22:04', '2018-08-23 14:22:04'), (20, 541, '2018-08-23 14:22:04', '2018-08-23 14:22:04'), (21, 541, '2018-08-23 14:22:04', '2018-08-23 14:22:04'), (22, 541, '2018-08-23 14:22:04', '2018-08-23 14:22:04'), (23, 541, '2018-08-23 14:22:04', '2018-08-23 14:22:04'), (24, 541, '2018-08-23 14:22:04', '2018-08-23 14:22:04'), (25, 541, '2018-08-23 14:22:04', '2018-08-23 14:22:04'), (26, 541, '2018-08-23 14:22:04', '2018-08-23 14:22:04'), (27, 541, '2018-08-23 14:22:04', '2018-08-23 14:22:04'), (28, 541, '2018-08-23 14:22:04', '2018-08-23 14:22:04'), (29, 541, '2018-08-23 14:22:04', '2018-08-23 14:22:04'), (30, 541, '2018-08-23 14:22:04', '2018-08-23 14:22:04'), (31, 541, '2018-08-23 14:22:04', '2018-08-23 14:22:04'), (32, 541, '2018-08-23 14:22:04', '2018-08-23 14:22:04')
```
This does not occur on additional runs, just the initial one.
Manually triggered synchronization does not have this, only syncplan-triggered.
However it is not 100% reproducible.
It is exclusive to FIPS enabled machine, does not occur on non-fips under same cicumstances.
Backtace in supplement.
Files