Bug 1737790

Summary: improve error message "error: internal error: Duplicate key"
Product: Red Hat Enterprise Linux 8 Reporter: yafu <yafu>
Component: libvirtAssignee: Ján Tomko <jtomko>
Status: CLOSED ERRATA QA Contact: chhu
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 8.1CC: chhu, jdenemar, jtomko, rbalakri, yalzhang
Target Milestone: rc   
Target Release: 8.0   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: libvirt-4.5.0-32.el8 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2019-11-05 20:51:11 UTC 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:

Description yafu 2019-08-06 08:52:05 UTC
Description of problem:
When trying to define a guest while the guest is removing, incorrect error message report:
"error: internal error: Duplicate key"

Version-Release number of selected component (if applicable):
libvirt-4.5.0-31.module+el8.1.0+3808+3325c1a3.x86_64

How reproducible:
100%


Steps to Reproduce:
1.# virsh create vm1.xml; virsh destroy vm1& virsh define vm1.xml;sleep 1; virsh undefine vm1;
Domain vm1 created from vm1.xml

[1] 26608
Domain vm1 destroyed
error: 
Failed to define domain from vm1.xml
error: internal error: Duplicate key

[1]+  Done                    virsh destroy vm1
error: failed to get domain 'vm1'
error: Domain not found: no domain with matching name 'vm1'

Actual results:
The error info is not helpful.

Expected results:
Improve the error message.


Additional info:

Comment 1 Ján Tomko 2019-08-06 10:55:36 UTC
Fixed upstream by:
commit a5c71129bf2c12a827f1bc00149acd1c572ffe9c
Author:     Michal Privoznik <mprivozn>
CommitDate: 2019-04-04 09:16:24 +0200

    virDomainObjListAddLocked: Produce better error message than 'Duplicate key'
    
    If there are two concurrent threads, one of which is removing a
    domain from the list and the other is trying to add it back they
    may serialize in the following order:
    
    1) vm->removing is set and @vm is unlocked.
    2) The tread that's trying to add the domain onto the list locks
       the list and tries to find, if the domain already exists.
    3) Our lookup functions say it doesn't, so the thread proceeds to
       virHashAddEntry() which fails with 'Duplicate key' error.
    
    This is obviously not helpful error message at all.
    
    The problem lies in our lookup functions
    (virDomainObjListFindByUUIDLocked() and
    virDomainObjListFindByNameLocked()) which return NULL even if the
    object is still on the list. They do this so that the object is
    not mistakenly looked up by some driver. The fix consists of
    moving 'removing' check one level up and thus allowing
    virDomainObjListAddLocked() to produce meaningful error message.
    
    Signed-off-by: Michal Privoznik <mprivozn>
    Reviewed-by: Cole Robinson <crobinso>

git describe: v5.2.0-114-ga5c71129bf contains: v5.3.0-rc1~253

Comment 4 chhu 2019-08-28 03:45:55 UTC
Verified on packages:
libvirt-4.5.0-33.module+el8.1.0+4066+0f1aadab.x86_64

Get error messge:"error: operation failed: domain 'r8' is already being removed"
other than "error: internal error: Duplicate key". Set the bug status as "Verified"
Rerun 10 times, virsh command work well, libvirtd service work well.

Set the bug status to "VERIFIED".

Test steps:
# virsh create r8-1.xml; virsh destroy r8& virsh define r8-1.xml; sleep 1; virsh undefine r8
Domain r8 created from r8-1.xml

[1] 14440
Domain r8 destroyed
error: Failed to define domain from r8-1.xml
error: operation failed: domain 'r8' is already being removed
[1]+  Done                    virsh destroy r8
error: failed to get domain 'r8'
error: Domain not found: no domain with matching name 'r8'

# virsh list --all
 Id    Name                           State
----------------------------------------------------

Comment 6 errata-xmlrpc 2019-11-05 20:51:11 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.

https://access.redhat.com/errata/RHSA-2019:3345