Bug 2216471

Summary: Can't delete host right after facts gathered - foreign key violation
Product: Red Hat Satellite Reporter: Lukáš Hellebrandt <lhellebr>
Component: FactAssignee: satellite6-bugs <satellite6-bugs>
Status: NEW --- QA Contact: visawant
Severity: medium Docs Contact:
Priority: unspecified    
Version: 6.14.0CC: rlavi, shwsingh
Target Milestone: UnspecifiedKeywords: Triaged
Target Release: Unused   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
production.log none

Description Lukáš Hellebrandt 2023-06-21 14:19:21 UTC
Description of problem:
Sometimes, when I try to delete a host right after I played its ansible roles and facts import got triggered in background, I get ISE and a foreign key violation. Looks like race condition when host deleting starts and before it is finished, its facts are imported and deletion fails.

Version-Release number of selected component (if applicable):
Reproduced on Sat 6.15 stream snap 18.0, I don't have a reason to think it's a regression but I haven't tested.

How reproducible:
Random. I was able to reproduce in automation using API when the client was RHEL8, perhaps because it has more facts than RHEL7. Adding a few seconds sleep between play-roles and host delete proved as workaround.

Steps to Reproduce:
Run facts on a RHEL8 host and delete it immediately.

Actual results:
ISE 500:
Backtrace for 'Action failed' error (ActiveRecord::InvalidForeignKey): PG::ForeignKeyViolation: ERROR:  update or delete on table "hosts" violates foreign key constraint "fact_values_host_id_fk" on table "fact_values"

Expected results:
Host removed, or at least delete failed gracefully

Additional info:
production.log including traceback attached

Comment 1 Lukáš Hellebrandt 2023-06-21 14:27:18 UTC
Created attachment 1971893 [details]
production.log

Attaching traceback for testcase failure

Comment 2 Lukáš Hellebrandt 2023-06-21 14:37:17 UTC
Created attachment 1971894 [details]
production.log.pass

Attaching a log for instance where it passed. Note a different order of fact import action and host delete action. Where it failed, import finished after delete started.